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
...
}
...
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)
...
}