簡體   English   中英

Google表格> Google表格> Google Code =電子郵件通知

[英]Google Form > Google Sheet > Google Code = email notification

我不確定該在哪里發布。 我希望這是正確的地方。

我有一個Google表單,填寫表單后,回復會自動輸入到Google表格中。 由於我是所有者,因此我已經設置了默認的Google通知,該通知會告訴我無論何時填寫Google表單,表單都已更改:

流程是:填寫Google表單> Google表格已更新,其中包含表單>電子郵件通知對我的電子郵件地址的回復

我已將Google表格共享給公司中的其他用戶。 他們具有工作表的編輯權限。 我希望此用戶也可以在表單更改時收到通知。

因此,流程將是:填寫Google表單> Google表格更新,其中包含表單的回復>發送給我的電子郵件通知以及其他用戶的電子郵件地址

我已經在線搜索過,因為目前尚無法在Google Apps中搜索(它只會通知所有者)。 建議在我的Google表格上創建自定義Google代碼,如下所示:

function myFunction() {
    MailApp.sendEmail("myemailaddress@mybusiness.com","Notification - Change in Spreadsheet","Notification - There has been a change in the Spreadsheet. Please view the change here: (I've put the url of sheet here) ");

    MailApp.sendEmail("theotheruser@mybusiness.com","Notification - Change in Spreadsheet","Notification - There has been a change in the Spreadsheet. Please view the change here: (I've put the url of sheet here) ");
}

當我從代碼編輯器運行此代碼時,它會向我和其他用戶發送我想要的自定義Google代碼通知電子郵件。

填寫表單后,表格中的響應會更新,我會從官方Google通知中收到有關更改的電子郵件通知。 我和其他用戶沒有收到自定義Google Code電子郵件通知。

我在“觸發器”部分瀏覽了Google Code網站,但不確定如何編寫此部分。 我想我需要在代碼上寫一個觸發器,該代碼說工作表已更改時運行自定義代碼。

因此,填寫的Google表單>已用來自表單的響應更新的Google表格> Google表格中的更改觸發了觸發器>觸發器運行自定義Google Code>另一個用戶,我收到了自定義Google Code電子郵件通知。

任何人都可以提供有關觸發代碼部分的幫助,甚至可以推薦其他解決方案嗎?

謝謝。

您可以在腳本編輯器的“資源”->“當前項目的觸發器”菜單項中添加觸發器。

然后以以下格式創建觸發器:

“ myFunction”->“從電子表格”->“更改時”

對於觸發器,我之前做了類似的代碼,但這是用於onChange事件。 您在這里明確需要的是“ OnFormsubmit”觸發器。 下面是我使用自定義菜單編寫的帶有內聯注釋的代碼;

// Written by Madzihi
// on a nice Sunday afternoon

function onOpen(){    //Setting up all the custom menu components
        var ss = SpreadsheetApp.getActiveSpreadsheet();    //Get the current active Spreadsheet
        ss.addMenu('Custom Setup',[{name:'Select Sheet',   //Assemble all the menu's component
                                functionName:'openSheet'},{name:'Set Trigger',functionName:'triggerSet'},
                                {name:'Delete Trigger',functionName:'delTrigger'}]);
        ss.addEditor(Session.getActiveUser().getEmail());   //This line set up so editor(s) don't have to run manually the script to gain authorization
}
function triggerSet(){    //Function to setting up the triggers for current project 
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var ui = SpreadsheetApp.getUi();    //Get the UI for setting trigger
    var triggers = ScriptApp.getProjectTriggers();    //Get the current project's trigger
    var respond = ui.alert('Setting up new trigger', ui.ButtonSet.OK_CANCEL);    //Set the UI prompt message and 'OK/CANCEL' buttons
        if(respond ==ui.Button.OK && triggers <=1){   //Set the trigger if button 'OK' is clicked and prevent trgger to be installed more than 1
        ScriptApp.newTrigger('onChanges').forSpreadsheet(ss).onChange().create();   //Line for creating the trigger based on changes that made in google sheet
        }
        else if (respond == ui.Button.CANCEL){    //If 'CANCEL' button is clicked will alert user no trigger installed
        ui.alert('No new trigger have been installed');
        }
        else { ui.alert('No new trigger have been installed')    //If close button is clicked will alert user no trigger installed
        }
}
function delTrigger(){    //Setup for deleting trigger
    var ui= SpreadsheetApp.getUi();
        try{
        var triggers = ScriptApp.getProjectTriggers();
        ScriptApp.deleteTrigger(triggers[0]);    //Choosing the trigger to be deleted
        ui.alert('Your trigger have been deleted');
           }
        catch(e){
           ui.alert('No trigger have been set!');    //If there is no trigger have been set, it will throw this alert to user.
        }
}

該行應替換我編寫的代碼中的當前觸發器生成器。 編輯器和您將需要單擊任何自定義菜單一次以激活授權。

ScriptApp.newTrigger('onChanges').forForm(key).onFormSubmit().create(); 

上面這一行的解釋:

  • “ onChange”是將被觸發的函數名稱
  • “鍵”是與電子表格綁定的表單的鍵/唯一ID。

希望這里對您有所幫助,如果有任何評論。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM