0
votes

I know that installable triggers run as the author of the script. But some services, like email service will work only from installable trigger.

I need to use simple trigger to check if current user has access to edit the specific range and installable trigger to send email.

I have code like this:

var MY_VARIABLE;

function onEdit() {    
  MY_VARIABLE = 'onEdit was here!'     
}

function myOnEdit() {
// installable trigger
    Browser.msgBox(MY_VARIABLE);

    // send email, use email service
}

The result is undefined.

And I'm willing to have 'onEdit was here!'

1
You can let onEdit update the script properties and let another trigger check every minute if there was an update and then send an e-mail. (Script properties: developers.google.com/apps-script/reference/properties/…) - Wim den Herder

1 Answers

2
votes

if you write something like:

function onEdit() {    
  MY_VARIABLE = 'onEdit was here!';
  myOnEdit();  
}

function myOnEdit() {
    Browser.msgBox(MY_VARIABLE);
}

it will work. But if "myOnEdit" is not call at the same time than "onEdit" the script will forgot everything. Each time the stript is triggered (onEdit or when you manually launch a function) the environment is reset and the content of "MY_VARIABLE" is forgotten.
What Wim den Herder proposed on his comment is the good solution, you need to store "MY_VARIABLE" value somewhere Google Apps Script can remember through the differences instances of the script. That's what the propertyService allow. One last thing, propertyService needs authorisation to be run. So you can't really use a function that's called "onEdit" for it to be run at every cell modification, you need to rename that function (for whatever you want) and set a onEdit trigger on it.