4

I am trying to create an installable onEdit trigger for a spreadsheet bound script. I would like to do this programmatically with a separate, standalone script. It looks like this should be possible according to documentation:

Note that, unlike for a simple onOpen() trigger, the script for the installable trigger does not need to be bound to the spreadsheet. To create this trigger from a standalone script, simply replace SpreadsheetApp.getActive() with a call to SpreadsheetApp.openById(id). https://developers.google.com/apps-script/guides/triggers/installable#managing_triggers_programmatically

However, when I run the code below, the trigger is added to the standalone script project instead of the target, spreadsheet-bound script.

function createSpreadsheetEditTrigger() {
  var ss = SpreadsheetApp.openById('1vcAgQ6vPZiILFX0fB_jojyrSdGKr7goD_iCQcFsImEM');
  ScriptApp.newTrigger('update')
   .forSpreadsheet(ss)
   .onEdit()
   .create();
}

What am I missing?

1 Answer 1

3

Well, this may be possible, but not like that. I think you misunderstood the documentation a bit. Putting in other words, what it says is: to create a installable trigger, a script does not need to be bounded to the target spreadsheet. But the trigger is for the running script itself, as always. There's no installing a trigger for another script.

Scripts can only set triggers for themselves, and there's no API to set a trigger for another script.

You could have the bounded script published as a web-app, then the remote standalone script could call its URL, basically "telling" the bounded script that it's time to set its installable trigger.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, this makes much more sense now. So tell me if this is right: I could create a standalone project with two functions (say functionA() and functionB()), and have functionA() create a trigger which would call functionB() when a given spreadsheet is edited.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.