2016-12-08 57 views
1

我想使用触发器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(); 
} 
+0

你应该做的第一件事是查看执行文件。在日志打印输出的底部,应该有关于脚本是否完成的声明,如果不是,则说明错误发生在哪一行。 –

+0

这是表单中或接收电子表格中的脚本? –

+0

@Karl_S此脚本仅适用于 –

回答

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

+0

表单感谢您的帮助,但是我发现问题实际上来自表单编辑器中的Ui函数与despondence。 –

0

问题是UI功能不能用于形成反应,但只有到编辑器,而我试图添加一个“弹出式”对话框来检查权限。目前,Google表单响应的创建弹出式对话框没有解决方法。