问题
I am trying to learn Google App Scripts. I have a form with one question. Then I created a new spreadsheet for the responses. Then from the form I went to the script editor. I installed a new trigger for the function onSubmit(e).
I wanted to modify the spreadsheet for responses. The event object should pass in the range that was just added. But every time I submit the form nothing happens in the spread sheet. I have the code below.
function onSubmit(e){
var range = e.range;
range.setNote('changed');
}
回答1:
In fact, Bayani, I think the trigger works from both. The thing is when the trigger is in the form, the triggered function tries to read the spreadsheet too soon, before Google Forms service update it with the submitted data of the form. (Sorry for adding a new answer, but my reputation score doesn't allow me to add comments yet - And very sorry because when I was writing this answer I accidentally clicked in your answer for editing and changed an "from" to an "in": please, just reject my edit).
回答2:
I figured it out. When you create scripts for the form and the associated spreadsheet, you can do it from both. But if you create it in the form, the event object won't work with the spreadsheet. But if you create it from the spreadsheet, you can still use the form submit trigger. But this time the event object will work.
来源:https://stackoverflow.com/questions/39068904/event-object-for-form-submit-on-google-apps-script-not-working