2016-12-08 63 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表單響應的創建彈出式對話框沒有解決方法。