我在一張特定的電子表格中有兩張表格,這兩張表格都與表格提交相關聯。第一張表單應該發送一封包含表單提交數據的電子郵件(原件由Amit Agarwal創建,這裏是an historic link)。第二張表格沒有做任何特殊的事情,因爲它只是從表格中收集數據。有問題的腳本設置爲On Form Submit觸發器。確保表單提交觸發器只運行一張工作表
我遇到的問題是腳本有時從表單/表單2運行。我想指定腳本需要觸發哪個表單/表單來運行。我創建的修改後的代碼基於大量環顧四周。下面是摘錄:
function Initialize() {
var triggers = ScriptApp.getProjectTriggers();
for (var i in triggers) {
ScriptApp.deleteTrigger(triggers[i]);
}
ScriptApp.newTrigger("SendConfirmationMail")
.forSpreadsheet(SpreadsheetApp.getActiveSpreadsheet())
.onFormSubmit()
.create();
}
function SendConfirmationMail(e) {
try {
var ss, bcc, sendername, subject, columns;
var message, value, textbody, sender;
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = ss.getSheetByName('Help Request Tickets');
var rowNumber = s.getActiveRange().getRowIndex();
var row = e.range.getRow();
// This is your email address and you will be in the BCC
bcc = "email", "email";
// This will show up as the sender's name
sendername = "sendername";
// Optional but change the following variable
// to have a custom subject for Google Docs emails
subject = "subject"
// This is the body of the auto-reply
message = "message"
ss = SpreadsheetApp.getActiveSheet();
columns = ss.getRange(1, 1, 1, ss.getLastColumn()).getValues()[0];
這兩行我雖然被認爲做到這一點:
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = ss.getSheetByName('Sheet1');
我想劇本認爲Sheet2中是有效的(這要是我有電子表格開放可能的情況下)。當然有辦法解決/完成這個,我錯過了什麼?
Amit更新了最初包含該代碼的博客條目,現在描述安裝和使用他的Google表單插件。但是,在該backback機器中該帖子的最早版本具有代碼,但是:[here](https://web.archive.org/web/20140126020722/http://www.labnol.org/internet/auto-confirmation-電子郵件/ 28386)。 – Mogsdad