I automatically create a form with GAS as follows:
var form = FormApp.create(form_name);
ScriptApp.newTrigger('mysubmit')
.forForm(form)
.onFormSubmit()
.create();
The problem is that it creates a trigger every time new form is created. Is there a way to reuse the same trigger? A problem is that a number of triggers available to my account runs out very quickly.
My workaroung but still 20 triggers limit exists
function install_submit_trigger(form, fids)
{
var allTriggers = ScriptApp.getProjectTriggers();
for(var i = 0; i < allTriggers.length; i++)
{
ScriptApp.deleteTrigger(allTriggers[i]);
}
for(var i in fids)
{
var fid = fids[i];
try
{
ScriptApp.newTrigger('mysubmit')
.forForm(FormApp.openById(fid.fid))
.onFormSubmit().create();
}
catch(e)
{
Logger.log("Error adding trigger: " + e);
}
}
ScriptApp.newTrigger('mysubmit') .forForm(form) .onFormSubmit() .create();
}
If you use an Apps Script to create a Form and then create a form submit trigger for that Form, the trigger you have created is attached to the script , not the new Form. This is why you are running into the 20 triggers / user / script quota limit .
Keep in mind that triggers live on scripts, not Docs, Sheets, or Forms. You can use a script to create a new Form, but you can't use a script to create a new script attached to that Form (scripts cannot create other scripts). This means you cannot programmatically create a trigger that lives on another document.
What you can do is create a Forms add-on that, when a new Form is created, a user can hit a menu control to create a form submit trigger for that Form.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.