I have a google sheet that has custom scripts in it. It is used as a template and is replicated for each project we have. In order to have the sheet be updated in the future with new scripts, I created a "Library" document and published the scripts as a library.
Everything works fine for me the owner of the document. If I update the library script sheet document it shows up correctly on an older sheet document. However other people in the company do not see the update.
Here is the script in the normal document. (I've removed other functions not relevant to the issue)
// all functions can be found in Customer_notes_Library spreadsheet https://docs.google.com/spreadsheets/d/*********
function onOpen() {
CustomerLibrary.onOpen();
}
Here is the script in the Library Template
devmode:false
// This will run when sheet is opened and add a drop down menu for us to add custom global functions. We have added a Sonicwall Setup Menu option
function onOpen() {
SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
.createMenu('Realm Custom Scripts')
.addItem('DHCP Bash Script', 'runBuildDHCPBashScript')
.addItem('IP Adress Input', 'runBuildDHCPIpAdressInput')
.addItem('Wire Device Input', 'runBuildDHCPIpAdressInput')
.addItem('Client Music Request', 'runClientMusicFormRequest')
.addToUi();
}
These drop-down menus are not updating for other users but is updating for me the owner.
I believe the issue is the onOpen function and there needs to be some way for the user to reauthorize access to the sheet that has the library in it after the scripts in the library have been updated.
I see someone had a similar issue here. But I'm unable to follow the solution.
https://productforums.google.com/forum/#!topic/docs/BJd8zRYD1qU;context-place=forum/docs
I also read that setting devmode to false might be helpful, not sure if I am doing that correctly or not.
Any help and if need further detail please let me know.
Related
For months I'm trying, without success, to submit my Google Sheets Add-On to be available at Google Workspace Marketplace. On the last tentatives I'm receiving this message:
The App doesn’t meet the publishing review criteria on the following:
Menu - Menu options not shown after App is installed. Please ensure that the add-on correctly uses onInstall() and onOpen() to populate its menu. The menu items populate when the add-on is first installed and when a different file is opened. See Editor add-on authorization.
My question is: How can I simulate the installation by myself in order to detect what function or variable is causing the problem?
I already try to avoid declaring Global variables, tried zillions of different ways to populate the menu, but it seems that nothing work. The documentation of Google Apps Script is too generic, the people at GWM doesn't show what error is happening. I really doesn't know what can I do.
How can I avoid a situation that I cannot replicate?
If I just have access to the my own add on GWM page to test it.
Sometimes I ask myself if Google is interested in have third party add on. It's so hard to have information.
Any help will be welcomed.
This is my initialization routine right now:
var ui = function(){
return SpreadsheetApp.getUi()}
/**
* #OnlyCurrentDoc
* ver: https://developers.google.com/apps-script/guides/services/authorization
*/
// The onOpen function is executed automatically every time a Spreadsheet is loaded
function onOpen(e) {
ui().createAddonMenu()
.addItem('Importar fontes', 'ExtrairComentarios')
.addSeparator()
.addItem('Relação de fatores', 'doFactors')
.addItem('Análise simples', 'doTable')
.addItem('Georreferenciamento', 'doMap')
.addSeparator()
.addItem('Gera matriz multimodal', 'GeraMatrizMM')
.addItem('Análise multimodal', 'doMultimodal')
.addItem('Gráfico multimodal', 'doGet')
.addItem('Gráfico multifatorial', 'doMultifatorial')
.addSeparator()
.addItem('Tutorial', 'openTutorial')
.addSeparator()
.addItem('Versão atual', 'DoVersaoAtual')
.addItem('Start!', 'DoStart')
.addToUi();
// Script external request
//eval(UrlFetchApp.fetch("https://cdnjs.cloudflare.com/ajax/libs/alasql/0.6.2/alasql.min.js").getContentText())
}
/**
* The event handler triggered when installing the add-on.
* #param {Event} e The onInstall event.
*/
function onInstall(e) {
onOpen(e);
}
P.S. Believed me, I already spend months trying to solve this.
Google recently released a way to test Editor add-ons and updated the docs. See https://developers.google.com/apps-script/add-ons/how-tos/testing-editor-addons
Now it's possible to create a test deployment for Editor add-ons. Please checkout the details on the previous link.
If you have a Google Workspace account, an alternative might be to publish the add-on for internal use only for testing purposes. Once you have it working you might make a copy to publish publicly, and keep the internal use only for testing future changes.
To prevent having problems use the simple onOpen trigger only to show the custom menu. If you want that the add-on does something else on open, do that using an installable trigger, this imply to add a way for the end-user to create this trigger, i.e. include a option on the custom menu for that.
Issue
I have a container-bound script attached to my document.
It has onOpen installable trigger and I need to get the script in newly created documents.
The most effective way I found is to create the new documents by copying from the original document.
The problem is, that the triggers are not copied with it.
Conditions:
Simple triggers are not enough, I need to use action requiring authorization
I don't want to force my users to create manually trigger for each document
I don't mind if the installable trigger is created after clicking button from the programmatically created menu
My thoughts:
I wanted to create it programmatically – there is a problem with the testing environment. I am getting an error:
The add-on attempted an action that is not permitted in Test as add-on
mode. To use this action, you must deploy the add-on.
as I understood, I need to release the project to the store to use this, which I don't want to do.
I don't mind release as an add-on, but the google script IDE only offers to release as web Docs web add-on.
Code:
function onOpen(e){
DocumentApp.getUi() // Or DocumentApp, SlidesApp, or FormApp.
.createMenu('Custom menu')
.addItem('Open sidebar automatically', 'createTrigger')
.addToUi();
}
function createTrigger() {
var doc = DocumentApp.getActiveDocument();
ScriptApp.newTrigger('onOpenReal')
.forDocument(doc)
.onOpen()
.create();
}
function onOpenReal(e){
...something requiring authorization...
}
I figured the answer partially:
I think it is not possible to copy the document together with its triggers, but I didn't find any official documentation about that.
But the error:
The add-on attempted an action that is not permitted in Test as add-on
mode. To use this action, you must deploy the add-on.
in the seemingly regular environment was caused by saved test configuration in the Google apps script editor.
To get rid of the error you need to first delete all test configurations in "Test as add-on" option. Until that the system sees all launches as "test" even if opened as a regular user.
I recognized that when I am creating a new Project in script.google.com, than there is no way to join it to a sheet.
I mean when I am creating a new sheet and open script editor in it, I have a new "Untitled Project". However I would like to have there one of my projects inside.
Like "import" project to a sheet.
I still can not understand the librarys. Google Docs Translator example
In this example we have a script. In this script are functions like
function onInstall(event){
onOpen(event);
}
function onOpen(event) {
SlidesApp.getUi().createAddonMenu()
.addItem('Open Translate', 'showSidebar')
.addToUi();
}
function showSidebar() {
var ui = HtmlService
.createHtmlOutputFromFile('sidebar')
.setTitle('Translate');
SlidesApp.getUi().showSidebar(ui);
}
But if I going to use librarys, despite I see AddOnMenue which is inside onOpen(), I can not run the function "showSidebar()" because the new sheet only recognized the onOpen() but not the other functions... so I got an error. What is wrong on the schematic?
In my personal script I have about 30 functions. I thought that I can just save the Version, copy the Script Id and use the script within several sheets. But I do not understand the key schematic and why I got an error.
Projects are contained in the Spreadsheet not the sheets. Projects can access any sheet or even any spreadsheet via openById(). Yes StandAlone projects are not contained in Spreadsheets. That's why they're called standalone.
I have
an Apps Script Library 'MyLib'.
template Google Spread Sheet ('MyGSSheet'). Through Script Editor I added the library 'MyLib' to 'MyGSSheet'. I set 'Development mode' 'on'.
users get a 'copy' of this template ('MyGSSheet').
How can I have a setup wherein any changes I make to 'MyLib' get picked up across these copies automatically (once the Spreadsheet is reloaded)?
I thought having 'Development mode' 'on' is all that's needed for this continuous update of the code in all the Spreadsheets.
However, I don't see this happening. The copies aren't picking the latest code.
I also granted 'edit' permission to all users within our company domain.
I am not able to comment so I hope I am contributing enough to justify an answer..
So I tried to reproduce this:
I created a standalone App Script 'MyLib' and wrote a single function:
function myFunction()
{
SpreadsheetApp.getUi().alert("TEST");
}
Next I created a spreadsheet and added a script to it via Tools. I'll call it "Spreadsheet Script".
In the Spreadsheet Script I added the MyLib as a library and turned the development mode 'on'.
Also I added two functions to Spreadsheet Script:
function onOpen(e)
{
myFunction();
}
function myFunction()
{
MyLib.myFunction();
}
Ok, now I shared the Spreadsheet and the MyLib - script to my colleague with edit rights. He opened the spreadsheets and got the alert "TEST".
Now when I modified the alert text from the MyLib-script's myFunction to "TEST 2 " and just saved the file (File/Save, did not save a new version), my colleague saw the changes in the spreadsheet. Then, I made him to take a copy of the spreadsheet( To test the effect of the spreadsheet owner change).
I changed the alert the text to "TEST 3". The change was reflected in his copy of the spreadsheet.
Are you able to reproduce this or does this approach fail to update for the other users? I am choosing this kind of simple example as sometimes the reason might reside in the code too...
I've created a number of email scripts for our company's internal usage. Usually I create the script, save and then when I open the spreadsheet I can go to the Tools > Script Manager and run the script.
It is not showing up - only Script Editor and Script Gallery.
The script is not a "stand alone" script - I created it from the spreadsheet's Script Editor.
Is this something that has been disabled in the new Google spreadsheets? Or is there something else I need to code in the script to have it work?
Thank you.
As others have pointed out, it's been removed, but it's pretty easy to create a custom menu to call your method from:
Let's say you have a method myCustomMethod that you want to run from Google Sheets. Open the Script Editor and add the following code:
function onOpen() {
var ui = SpreadsheetApp.getUi();
ui.createMenu('Custom Menu')
.addItem('Run custom method', 'myCustomMethod')
.addToUi();
}
Reload your sheet and you should see a new top-level menu next to Help, called "Custom Menu".
If you are using the new version of Sheets then the "Script Manager" is no longer a feature now as the New Sheets uses "Add-ons". You may find the resource on the link:
https://support.google.com/docs/answer/2942256?hl=en
I don't remember a 'Script Manager' setting, but I always run it from the script itself, so maybe I just wasn't looking. It has apparently been removed for some time so you may instead need to consider creating a custom menu to run any function of the script.
Edit: I had a dig about an old version of sheets, and I could confirm this was in the old version:
But has been removed from the new version of sheets.