'Problem when setting onFormSubmit trigger from spreadsheet to form
I've made a script that builds different forms and they have assigned an onFormSubmit trigger. On the trigger, I have this trouble.
const form = FormApp.getActiveForm()
but the problem is that that script is bounded on the script that builds the forms, not into the form instead. I can't open the form with the Id because it wouldn't work for all the forms
SpreadSheet script
function main(){
...
const formId = form.getId()
//setup trigger
ScriptApp.newTrigger('onFormSubmit')
.forForm(formId)
.onFormSubmit()
.create()
}
function onFormSubmit(e){
...
const formResponse = e.response;
const date = formResponse.getTimestamp()
const names = getNames()
...
}
function getNames(){
...
const form = FormApp.getActiveForm() //problem
...
}
...
Solution 1:[1]
I've solved it by getting the source info from the event parameter
function onFormSubmit(e){
...
const formResponse = e.response;
const date = formResponse.getTimestamp()
const formId = e.source.getId()
const names = getNames(formId)
...
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ramiro Pruis |
