1

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();
}
3
  • The first thing you should do is VIEW the EXECUTION TRANSCRIPT. At the bottom of the Log print out, there should be a statement about whether the script completed or not, and if not, what line the error occurred on. Commented Dec 9, 2016 at 2:02
  • This is a script in the Form or in the receiving spreadsheet? Commented Dec 9, 2016 at 16:42
  • @Karl_S This script is solely for the form Commented Dec 12, 2016 at 19:07

2 Answers 2

1

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: Clock Icon

Then go ahead and set up a new trigger: Set up

Select the function onSubmitTrigger() and you can set it up to run as the form is submitted: Set-Up

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your help, but I found out that the problem was actually from the Ui function in form editor vs despondence.
0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.