我建立的系統將執行以下操作:谷歌表/表單腳本截止日期提醒電子郵件發送錯誤的反應編輯鏈接
- 用戶提交
- 的確認電子郵件中的鏈接發送給編輯表單響應(到目前爲止好)的形式
- ,有一個「截止日期」的問題
- 觸發腳本掃描這些日期的每一天
- 當到期日已經到來,它會發送提醒郵件(這也發生公關operly,但) 在此提醒電子郵件
- ,編輯鏈接是重複的,這樣用戶不必搜索以前的郵件
可悲的是這個環節送出錯誤的。它不鏈接到正確的響應,而是鏈接到最後編輯(提交)的響應。
下面是腳本:
function sendReminderEmail() {
var sheet = SpreadsheetApp.getActiveSheet();
var startRow = 2; // First row of data to process
var numRows = sheet.getLastRow()-1; // Number of rows to process
// Fetch the range of cells A2:B3
var dataRange = sheet.getRange(startRow, 1, numRows, sheet.getLastColumn());
// Fetch values for each row in the Range.
var data = dataRange.getValues();
//Logger.log(data)
var form = FormApp.openById("IDremovedByMe");
var formResponses = form.getResponses();
var r = formResponses.length-1;
var editURL = formResponses[r].getEditResponseUrl();
//Get the Edit URL
for (i in data) {
var row = data[i];
var date = new Date();
date.setHours(0);
date.setMinutes(0);
date.setSeconds(0);
//Logger.log(date);
var sheetDate = new Date(row[13]);
//Logger.log(sheetDate);
var Sdate = Utilities.formatDate(date,'GMT+0100','yyyy:MM:dd')
var SsheetDate = Utilities.formatDate(sheetDate,'GMT+0100', 'yyyy:MM:dd')
Logger.log(Sdate+' =? '+SsheetDate)
if (Sdate == SsheetDate){
var sendTo = row[4]; // Collect email address from the fourth column (number value is always -1).
var sendMe = "[email protected]"; // Enter the email address where you wish to receive a notification about a reminder sent.
var sendername = "Auto Formbot"; // Name displayed as the sender.
var myname = "Formbot"; // Name displayed as the sender to you.
var messageTo = "Based on the data you entered, the '" +row[6] +"' project with the ID: " +row[1] +" has ended.\n\nPlease mark it as 'Completed' and update the details as soon as it's convenient for you.\n\nYou can edit your data by using the following link:\n" + editURL + "\n\nThank you for your time.\n\n\nWith kind regards,\nFormbot";
var messageMe = "The '" +row[6] +"' project with the ID: " +row[1] +" has finished today.\n\nA reminder email has been sent to " +row[4] +".\n\nYou can edit the data by using the following link:\n" + editURL + "\n\n\nSincerely,\nFormbot";
// Above is the column (number value is always -1) selected for activity name display.
var subjectTo = "Please update the '" +row[6] +"' activity data.";
var subjectMe = "An activity has finished today [ID: " +row[1] +"].";
MailApp.sendEmail(sendTo, subjectTo, messageTo, {name: sendername});
MailApp.sendEmail(sendMe, subjectMe, messageMe, {name: myname});
}
}
}
的問題顯然是這一部分:
var form = FormApp.openById("IDremovedByMe");
var formResponses = form.getResponses();
var r = formResponses.length-1;
var editURL = formResponses[r].getEditResponseUrl();
我只是不知道浩w解釋腳本如何獲得適當的響應。
也許我的做法是錯誤的,也許我應該告訴腳本掃描形式的數據庫,而不是鏈接的電子表格?任何想法如何做到這一點?
我可以想到兩種可能的解決方案。兩種可能的解決方案都涉及將一些額外信息保存到電子表格。最好的解決方案是將原始編輯URL保存到電子表格中。所以,不要從表單中獲取編輯網址。另一種解決方案是將響應ID保存到電子表格中,並通過ID查找正確的表單響應,然後從該響應中獲取編輯URL。這兩個解決方案看起來很簡單,但有一些複雜性。如果不是不可能在電子表格中找到正確的行來追加ID或編輯網址,這非常困難。 –
因此,您需要將所有數據保存到不同的電子表格中,而不是使用「內置」功能。因此,您需要進行更多編程才能將響應數據保存到完全不同的電子表格中,而不是使用「內置」功能的電子表格。您可以嘗試通過匹配時間戳和其他信息來查找表單中的正確響應,但可能在表單中具有多個完全相同的時間戳。所以,這不是一個可行的解決方案,除非您確定沒有人在同一秒內提交表格。 –
感謝您的建議,併爲最近的回覆感到抱歉。最後,我選擇在表格中記錄編輯網址並從那裏引用它們。 – mozzribo