Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

i've this simple script that should send an email when a cell is changed

function onEdit(e) {  

var doc = e.source; 

 var r = doc.getActiveRange().getValue();


 if (r == "Niccolò"){
var a = doc.getActiveRange().setBackground('#ff0000');
var b = GmailApp.sendEmail('[email protected]', 'subject', 'body');

}

}

This function change also cell colour. THe problem is that the cell colour works, so it's change while doesn't send any email. It looks so simple i don't understand why doesn't works!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
853 views
Welcome To Ask or Share your Answers For Others

1 Answer

Simple triggers like onEdit(), onOpen() or onFormSubmit() have a limited set of possible actions because they run without authorization , see the documentation for further details.

So this behavior you describe is normal.

You should use an installable trigger instead as explained in the same doc page.

here is an summary of the documentation :

These simple triggers run in response to actions in Google Spreadsheets, and they run as the active user. For example, if Bob opens the Spreadsheet, then the onOpen function runs as Bob, irrespective of who added the script to the Spreadsheet. For this reason, the simple triggers are restricted in what they are permitted to do: They cannot execute when the Spreadsheet is opened in read-only mode. They cannot determine the current user. They cannot access any services that require authentication as that user. For example, the Google Translate service is anonymous and can be accessed by the simple triggers. Google Calendar, Gmail, and Sites are not anonymous and the simple triggers cannot access those services. They can only modify the current Spreadsheet. Access to other Spreadsheets is forbidden. For more information on event permissions, see Executing from a Container-Specific Trigger.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...