Google script trigger 'from Spreadsheet' not available - google-apps-script

I've successfully created picklists from a Google sheet into a Google form following a tutorial (http://wafflebytes.blogspot.com/2016/10/google-script-create-drop-down-list.html) and Google's documentation, however I do not have the option to set a trigger on the Event 'From spreadsheet', as laid out in the the tutorials/documentation, so I must be missing a step and haven't been able to figure out what it is.
The result is that the options are not automatically updating and must be manually pushed. I would like to enable the options to be refreshed on open.
I do not have the option to updateForm + from spreadsheet, as pictured in those resources.
From tutorial
My options
What step am I missing? Or is this possibly a permissions issue (I am not owner of the documents, but I tried to reproduce this in docs I own and ran into the same issue)?
NOTE: I have not posted my script here because it's nearly identical to the one linked to in the tutorial.
Update:
I'm beginning more and more to think it has to do with our OAuth configurations or permissions. I even updated the manifest to explicitly authorize forms and sheets, but I'm still not offered sharing permissions. I will have our admin check in on this but if anybody has had experience in these matters, I'm all ears.

Since your options shows "From form", you are working on a project bounded to a form instead of the one that you created from your spreadsheet which is the one bounded to spreadsheet.
Rather than missing a tutorial step it could be that you had several script projects open at the same time and you are looking at the wrong one.
Reference
Event Objects

Related

Google blocks my Google Script that reads info from my Google Sheet to make slides in Google Slide project [duplicate]

I am unable to run any app script in my google account - even one created by me bound to a new document created by me. When I do, I get an "This App is Blocked" error. Note that this is different from the the "Sign in temporarily disabled for this app" failure mode mentioned elsewhere, and the solution for that problem has no effect on this one.
To test, I created a new spreadsheet while logged into my personal google account and put the value ONE in cell A1...
I then opened the Tools->Script editor from the menu bar of this spreadsheet and entered the following trivial script...
I then click on the run icon from the script editor menu bar with the function "myFunction" selected from the pulldown.
I get an "authorization required" popup and so I click "Review Permissions"...
I then get a "Choose an account" popup and click on my account (the only logged in account, and the same account I was logged into when I created the sheet and the script)...
I then get an "App Blocked" popup. Checking the execution log shows that the script did not run.
What is causing this popup and how can I prevent this so I can run app scripts?
NOTE: I see many other questions describing more complicated versions of this issue but none have useful answers. I am hoping this ultra simple version of the issue will help narrow it down and get a resolution.
More unexpected behavior:
If I put the code into the onLoad() function it works fine and never even asks me for authorization.
If I enter this code:
...and then quit out and reload the sheet, then I get this in the execution logs...
Again, this is with no authorization popups at all. The sheet loads without interruption and then the entry is in the execution logs. So this would seem to not be a case of not having the right permissions somewhere since code clearly can access the sheet.
Legacy editor
Identical behavior under the legacy editor...
Other accounts
I can repeat these exact same steps on a different google account and it works fine, so this problem appears to be linked to my account. Many others on the internet have noted the same finding. Seems like there might be some hidden (probably unintional) setting attached to the account that gets switched somehow and then thereafter the account is not able to manually authorize scripts to run.
Changing Project
I check and this script is in the "Default" project as expected...
According to this page,
For most applications and scripts, you never need to see or adjust this default GCP project—Apps Script handles all the necessary interactions with the Google Cloud Platform automatically.
Since I have nothing to lose, tried creating a new project in the Google Cloud Platform console, and then tried assigning this script to that new project. Unfortunately when I tried, I got the normal "Authorization needed" popup which lead to this opdd page...
Clicking on the "Troubleshoot this problem" link takes me to this page...
...which seems to say that I do not have the permissions to troubleshoot problems on my own account.
This again seems to suggest there is something misconfigured about my account on google servers. :/
Unfortunately there are no good answers there. Lots of people like me wake up one random morning to find that they can not run any new App Scripts in their account any more.
I've found a workaround that works great... but will make you very sad.
This issue does not affect code that runs automatically, so functions like onOpen() and onEdit() run just fine and have full access to the bound document. You heard that right- google blocks code that the user explicitly requests to run to protect their data, but code that runs silently and automatically anytime a sheet is opened or modified is free to run and access (and change!) whatever data it wants.
So to let the user run your code, you pick a cell inside the spreadsheet that either has a value that changes whenever you want your code to run, or you make a special cell called "Edit this cell to run the program".
Then you put your code inside the onEdit() and (if desired) check to see to see if the special cell was updated. If so, then run your arbitrary code. It has full access to the spreadsheet and can read and update cells at will and can also write to the log.
Note that you must close the sheet and re-open it for the code to take effect.
Here is what my demo spreadsheet looks like...
...and here is the demo code...
function onEdit(e) {
var range = e.range;
const triggerCell = "B2";
if( e.range.getA1Notation() === triggerCell){
var sheet = SpreadsheetApp.getActiveSheet();
var data = sheet.getDataRange().getValues();
var rangeB1 =sheet.getRange("B1");
var rangeB2 =sheet.getRange("B2");
var date = Utilities.formatDate(new Date(), Intl.DateTimeFormat().resolvedOptions().timeZone, "HH:mm:ss");
rangeB2.setValue("Code ran at " + date );
Logger.log( date + ": B1=" + rangeB1.getValue() );
}
}
Here is a demo video...
https://youtu.be/ypuLaUWn1R8
I've said it before, I'll say it again - if you were thinking about using Google Cloud Services for anything then think again. This is crap built on top of crap that no one at google understands and it occasionally breaks suddenly and catastrophically, and there is no one who can even tell you what is going on much less how or when or if it is going to get fixed.
I ran into this for the first time today but my issue seems to be due to:
created a sheet on a shared drive owned by a different organization
my organization uses the legacy apps script interface, the shared drive organization uses the new apps script interface
Using an account from the shared drive organization to create the script solved my issue.
This error
This app is blocked
seems to be a new error affecting certain Google accounts. This is reported to Google. Kindly star(add a star ★ to it on top left) to the following issues and comment to get Google developers to prioritize this issue:
https://issuetracker.google.com/issues/176138626
https://issuetracker.google.com/issues/181220763
Some workarounds:
#15 Creating a new GCP and linking it.
#12 Turning on Less Secure Apps
#10
Checking accounts security page
Turning off advanced protection
Unlock Captcha
This issue does NOT seem to be related to another issue 145162820:
"Sign in temporarily disabled for this app"
The error messages are different.

Unable to authorize ANY external Google Apps Script scope on any ANY file [duplicate]

I am unable to run any app script in my google account - even one created by me bound to a new document created by me. When I do, I get an "This App is Blocked" error. Note that this is different from the the "Sign in temporarily disabled for this app" failure mode mentioned elsewhere, and the solution for that problem has no effect on this one.
To test, I created a new spreadsheet while logged into my personal google account and put the value ONE in cell A1...
I then opened the Tools->Script editor from the menu bar of this spreadsheet and entered the following trivial script...
I then click on the run icon from the script editor menu bar with the function "myFunction" selected from the pulldown.
I get an "authorization required" popup and so I click "Review Permissions"...
I then get a "Choose an account" popup and click on my account (the only logged in account, and the same account I was logged into when I created the sheet and the script)...
I then get an "App Blocked" popup. Checking the execution log shows that the script did not run.
What is causing this popup and how can I prevent this so I can run app scripts?
NOTE: I see many other questions describing more complicated versions of this issue but none have useful answers. I am hoping this ultra simple version of the issue will help narrow it down and get a resolution.
More unexpected behavior:
If I put the code into the onLoad() function it works fine and never even asks me for authorization.
If I enter this code:
...and then quit out and reload the sheet, then I get this in the execution logs...
Again, this is with no authorization popups at all. The sheet loads without interruption and then the entry is in the execution logs. So this would seem to not be a case of not having the right permissions somewhere since code clearly can access the sheet.
Legacy editor
Identical behavior under the legacy editor...
Other accounts
I can repeat these exact same steps on a different google account and it works fine, so this problem appears to be linked to my account. Many others on the internet have noted the same finding. Seems like there might be some hidden (probably unintional) setting attached to the account that gets switched somehow and then thereafter the account is not able to manually authorize scripts to run.
Changing Project
I check and this script is in the "Default" project as expected...
According to this page,
For most applications and scripts, you never need to see or adjust this default GCP project—Apps Script handles all the necessary interactions with the Google Cloud Platform automatically.
Since I have nothing to lose, tried creating a new project in the Google Cloud Platform console, and then tried assigning this script to that new project. Unfortunately when I tried, I got the normal "Authorization needed" popup which lead to this opdd page...
Clicking on the "Troubleshoot this problem" link takes me to this page...
...which seems to say that I do not have the permissions to troubleshoot problems on my own account.
This again seems to suggest there is something misconfigured about my account on google servers. :/
Unfortunately there are no good answers there. Lots of people like me wake up one random morning to find that they can not run any new App Scripts in their account any more.
I've found a workaround that works great... but will make you very sad.
This issue does not affect code that runs automatically, so functions like onOpen() and onEdit() run just fine and have full access to the bound document. You heard that right- google blocks code that the user explicitly requests to run to protect their data, but code that runs silently and automatically anytime a sheet is opened or modified is free to run and access (and change!) whatever data it wants.
So to let the user run your code, you pick a cell inside the spreadsheet that either has a value that changes whenever you want your code to run, or you make a special cell called "Edit this cell to run the program".
Then you put your code inside the onEdit() and (if desired) check to see to see if the special cell was updated. If so, then run your arbitrary code. It has full access to the spreadsheet and can read and update cells at will and can also write to the log.
Note that you must close the sheet and re-open it for the code to take effect.
Here is what my demo spreadsheet looks like...
...and here is the demo code...
function onEdit(e) {
var range = e.range;
const triggerCell = "B2";
if( e.range.getA1Notation() === triggerCell){
var sheet = SpreadsheetApp.getActiveSheet();
var data = sheet.getDataRange().getValues();
var rangeB1 =sheet.getRange("B1");
var rangeB2 =sheet.getRange("B2");
var date = Utilities.formatDate(new Date(), Intl.DateTimeFormat().resolvedOptions().timeZone, "HH:mm:ss");
rangeB2.setValue("Code ran at " + date );
Logger.log( date + ": B1=" + rangeB1.getValue() );
}
}
Here is a demo video...
https://youtu.be/ypuLaUWn1R8
I've said it before, I'll say it again - if you were thinking about using Google Cloud Services for anything then think again. This is crap built on top of crap that no one at google understands and it occasionally breaks suddenly and catastrophically, and there is no one who can even tell you what is going on much less how or when or if it is going to get fixed.
I ran into this for the first time today but my issue seems to be due to:
created a sheet on a shared drive owned by a different organization
my organization uses the legacy apps script interface, the shared drive organization uses the new apps script interface
Using an account from the shared drive organization to create the script solved my issue.
This error
This app is blocked
seems to be a new error affecting certain Google accounts. This is reported to Google. Kindly star(add a star ★ to it on top left) to the following issues and comment to get Google developers to prioritize this issue:
https://issuetracker.google.com/issues/176138626
https://issuetracker.google.com/issues/181220763
Some workarounds:
#15 Creating a new GCP and linking it.
#12 Turning on Less Secure Apps
#10
Checking accounts security page
Turning off advanced protection
Unlock Captcha
This issue does NOT seem to be related to another issue 145162820:
"Sign in temporarily disabled for this app"
The error messages are different.

Using Google Script in shared, restricted spreadsheets

I wrote a script for a google spreadheet which is run by clicking on an image embedded in the spreadsheet.
Everybody with the link to the spreadsheet can edit it (except some areas with formulas etc. which are protected).
When I'm logged in with my google account, everything works fine, but when I log out and try using the spreadsheet like a "normal" user, nothing happens when I hit the image.
I didn't find anything in the options regarding "script sharing" etc.
Would be awesome if someone could give me a hint (I'm quite new to google script...).
Thanks for your answers!
Vincent
Anonymous users can't run scripts. By design. Protected ranges, sharing and all the rest of it have nothing to do with your problem.
The user - whoever they happen to be - must be logged in to run any script. Scripts will simply be ignored for anonymous users.
So the solution in your case is to tell all your users that they must log in before being able to run a script.

How can I let others install my Google Apps Script?

I've made a simple script in Google Apps Script. The script builds forms based on a spreadsheet, the script itself is part of the spreadsheet. It adds a menu item. People would like to use it. They are non-technical people, so I would like to make the installation of my script as easy as possible. With 'installation' I mean a way to 'import' my script into their spreadsheet and automatically set up the needed triggers so the menu item becomes visible. It should be possible for anyone to install it.
I've been thinking of the following solutions:
Publishing as an add-on: my script wouldn't qualify, and even then I can't wait for Google's approval.
Copy-paste. I don't like this, it's way too complicated.
I've looked at this question: https://stackoverflow.com/questions/5334751/how-do-i-share-a-script-i-wrote-with-my-co-workers-on-the-same-google-apps-accou, but the people wanting to install it are not on the same domain in my case. The question is also 3 years old.
EDIT: As it turns out, there doesn't seem to be a solution. I've filed a feature request here: https://code.google.com/p/google-apps-script-issues/issues/detail?id=4122&thanks=4122&ts=1403949074
If your Google Account administrator allows you, you can share scripts/spreadsheets outside your organisation either by sharing directly with another person with a Google Account (Gmail or Google Apps) or by making it public (share with a link or published online).
https://support.google.com/drive/answer/2494822?hl=en
Keep in mind that if you use the Script Properties to store values, each time someone uses the shared script it will overwrite the values. In a shared context it is best to use User Properties instead. This way each user can store their own values.
https://developers.google.com/apps-script/guides/properties
There is no way to import a script in an existing spreadsheet , the "normal" workflow is , in a way, the reverse process, that's to say create a sheet from an existing template that already has the script in it and start to work with that copy.
From your description I'm not sure this method could be useable but I'm afraid there is no other way if you want people who will be using it should not go into the script editor at all.
There would be a couple of functions to write that should run at install time and would create the triggers (if needed) and trigger the authorization process.
I made such a SS some time ago that needed authorizations and I added an "install" menu that made its use quite simple (example here on a friendly hosting site).
I know this is probably not the answer you were expecting but it was definitely too long to fit in a comment anyway.

Is it possible to have one script for multiple spreadsheets?

I have one master spreadsheet and a number of copies. This master spreadsheet uses some scripting.
Is it possible to link all the copies of this master spreadsheet to the same script as in the master spreadsheet?
Objective:
changes in the scripting in the master spreadsheet are automatically used by the copies
aka: low maintenance
amleczko is right: you should use the new library feature in Google Apps script.
However, as of today, you won't be able to do exactly what you want (using the same script for several spreadsheets). What you can do instead is save a version of your script (Files > Manage Versions...), in order to create a library. Then, import this library in the other spreadsheets (Resources > Manage Libraries...). Switch on the "development mode" so every change made do the library will immediately take affect in the spreadsheets using this library. Otherwise, you will have to save a new version of the library for every change, and manually update the version number of the library in every spreadsheets using it.
The problem is, you need to write a script in every spreadsheets using your library, with skeleton functions like this:
function doSomething(){
myLibrary.doSomething();
}
best way is to publish as add-on, then install the add-on, it will appears in every spreadsheet you open. and you can publish as private, which only seen by yourself.
I think this has changed. According to Issue 40 starting from 22 May 2012 there is such a possibility. Please check:
https://developers.google.com/apps-script/guide_libraries
https://developers.google.com/apps-script/guide_versions
http://googleappsdeveloper.blogspot.it/2012/05/introducing-versions-and-libraries-in.html
It's not possible in this way that you're thinking. At least, not yet (see issue 40).
But, depending on your script usage, you may connect them "the hard way" or even better, use only one script. The script on the master spreadsheet can open the other spreadsheet files and do its job "remotely". It's not required that script to be hosted on a spreadsheet to interact with it (read/write on it). You only need a script hosted on the spreadsheet if you're going to use spreadsheet events triggers i.e. on-open, on-edit and on-form-submit.
Maybe you can develop a nice UI for the script on the master sheet and publish it as service. Then only have a link on the copies to access the same UI on a different browser tab. Adding parameters to the link the script UI can even adapt to the particular spreadsheet that is "triggering" it.
Well, that's all I can imagine now. But, unfortunately, there's some use cases that just don't fit this nice "workarounds". For those, one can only star issue 40 (to kind of vote and keep track of updates) and hope it's developed soon.
The solution I put in place in this context was to have a Google Site, where the Master Script is embedded, and where the Spreadsheet is embedded too
Then, the script, refering to a dedicated spreadsheet, looks for the Google Site Page's name, looks in the Master spreadsheet and get the ID of the spreadsheet which is embedded in the Page.
I have solved this problem when using a script which auto generates spreadsheets.
Typically, I will add a sheet to any spreadsheet with a script called "Info." I'll use that to store information that it important to the script. In my script which auto generates more spreadsheets, I keep track of the ID of the created sheet. This way, I can then quickly call up all of the "linked" sheets, and interact with them with using the same script. It might even be worth writing the script in one sheet, and keeping it totally separate from your Master sheet or it's children.
Take a look at this function, it might give you some ideas.
SpreadsheetApp.openById(id)