Reputation: 11
I am trying to make the function run using the trigger onFormResponse. However, when I am testing with live form, nothing happens. I have tried deleting, recreating both trigger and the script, but it still does not work. Thank you for your help!
function onSubmit(e) {
//function get ID of the submitted response, log it to the console
//run a afunction that ask for permission to get a refilled URL
//based on the submitted one
//email the log to me
//get current form
var currentForm = FormApp.getActiveForm();
// Get ID of form on submited
var ID = e.response.getId();
Logger.log(ID);
checkPermission(currentResponse);
var recipient = Session.getActiveUser().getEmail();
var subject = 'Log';
var body = Logger.getLog();
MailApp.sendEmail(recipient, subject, body);
Logger.clear();
}
function checkPermission(e){
var ui = FormApp.getUi();
var dialogBox = ui.alert('Do you want to create a prefill form?',
FormApp.getUi().ButtonSet.YES_NO);
if(dialogBox == ui.Botton.YES){
var link = ui.alert(e.toPrefilledUrl());
}
}
function triggerTester(){
// create a an on form submit trigger for function onSubmit
var currentForm = FormApp.getActiveForm();
ScriptApp.newTrigger('onSubmit')
.forForm(currentForm)
.onFormSubmit().create();
}
Upvotes: 1
Views: 3859
Reputation: 11
The problem was the Ui functions cannot be applied to form response, but only to the editor, while I am trying to add a "pop-up" dialog box to check permission. Currently there is not a work around for creating a pop-up dialog box for Google form response.
Upvotes: 0
Reputation: 56
I'd try to comment but unfortunately I don't have enough reputation:
I would use this solution:
function onSubmitTrigger(){
//psuedocode(ish)
/*
1.Get range of values
2.Find last submitted value
3.Pass value to function "onSubmit"
*/
}
function onSubmit(e) {
//function get ID of the submitted response, log it to the console
//run a afunction that ask for permission to get a refilled URL
//based on the submitted one
//email the log to me
//get current form
var currentForm = FormApp.getActiveForm();
// Get ID of form on submited
var ID = e.response.getId();
Logger.log(ID);
checkPermission(currentResponse);
var recipient = Session.getActiveUser().getEmail();
var subject = 'Log';
var body = Logger.getLog();
MailApp.sendEmail(recipient, subject, body);
Logger.clear();
}
function checkPermission(e){
var ui = FormApp.getUi();
var dialogBox = ui.alert('Do you want to create a prefill form?',
FormApp.getUi().ButtonSet.YES_NO);
if(dialogBox == ui.Botton.YES){
var link = ui.alert(e.toPrefilledUrl());
}
}
function triggerTester(){
// create a an on form submit trigger for function onSubmit
var currentForm = FormApp.getActiveForm();
ScriptApp.newTrigger('onSubmit')
.forForm(currentForm)
.onFormSubmit().create();
}
You can set the trigger within the actual service: Click on the clock icon:
Then go ahead and set up a new trigger:
Select the function onSubmitTrigger()
and you can set it up to run as the form is submitted:
Upvotes: 1