表单上的Google脚本触发器无效

时间:2016-12-08 23:59:14

标签: google-apps-script google-form eventtrigger

我正在尝试使用触发器onFormResponse来运行该函数。但是,当我使用实时表单进行测试时,没有任何反应。我尝试删除,重新创建触发器和脚本,但它仍然无法正常工作。谢谢你的帮助!

   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();
}

2 个答案:

答案 0 :(得分:1)

我试着发表评论,但不幸的是我没有足够的声誉:

我会使用这个解决方案:

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();
}

您可以在实际服务中设置触发器: 点击时钟图标: Clock Icon

然后继续设置新的触发器: Set up

选择功能onSubmitTrigger(),您可以将其设置为在提交表单时运行: Set-Up

答案 1 :(得分:0)

问题是Ui函数不能应用于表单响应,而只能应用于编辑器,而我正在尝试添加“弹出”对话框来检查权限。目前,还没有为Google表单响应创建弹出对话框的工作。