[英]Write an email in HTML form containing jQuery and CSS through a Python script.
[英]Google Form. Confirmation Email Script. With edit url
我在Google腳本中有兩個工作觸發功能,當表單響應電子表格獲取新的提交時會觸發。 一個將“編輯您的提交” URL插入電子表格。 另一個查詢響應的電子郵件,並向他們發送確認。
就是我有一個很難理解的是如何先填充URL, 然后發送包含該URL的電子郵件。
( Google腳本與瀏覽器中的js調試不同:\\ )
設置觸發器
function Initialize() {
var triggers = ScriptApp.getScriptTriggers();
for (var i in triggers) {
ScriptApp.deleteTrigger(triggers[i]);
}
ScriptApp.newTrigger("SendConfirmationMail")
.forSpreadsheet(SpreadsheetApp.getActiveSpreadsheet())
.onFormSubmit()
.create();
assignEditUrls();
}
在提交表單時,搜索標題為“客戶電子郵件”的列,然后向他們發送格式化的電子郵件。
function SendConfirmationMail(e) {
try {
var ss, cc, sendername, subject, columns;
var message, value, textbody, sender;
var url;
// This is your email address and you will be in the CC
cc = Session.getActiveUser().getEmail();
// This will show up as the sender's name
sendername = "XXXX";
// Optional but change the following variable
// to have a custom subject for Google Docs emails
subject = "Form Complete: Mobile App - Client Questionnaire";
// This is the body of the auto-reply
message = "Confirmation text here.<br><br>Thanks!<br><br>";
ss = SpreadsheetApp.getActiveSheet();
columns = ss.getRange(1, 1, 1, ss.getLastColumn()).getValues()[0];
// This is the submitter's email address
sender = e.namedValues["Clients Email"].toString();
// Only include form values that are not blank
for ( var keys in columns ) {
var key = columns[keys];
if ( e.namedValues[key] ) {
message += key + ' :: '+ e.namedValues[key] + "<br />";
}
}
textbody = message.replace("<br>", "\n\n");
GmailApp.sendEmail(sender, subject, textbody,
{cc: cc, name: sendername, htmlBody: message});
} catch (e) {
Logger.log(e.toString());
}
}
分開的功能。 查找表單並將編輯URL應用於第26列。
function assignEditUrls() {
var form = FormApp.openById('10BVYipGhDa_AthabHE-xxxxxx-hg');
//enter form ID here
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Form Responses');
//Change the sheet name as appropriate
var data = sheet.getDataRange().getValues();
var urlCol = 26; // column number where URL's should be populated; A = 1, B = 2 etc
var responses = form.getResponses();
var timestamps = [], urls = [], resultUrls = [];
for (var i = 0; i < responses.length; i++) {
timestamps.push(responses[i].getTimestamp().setMilliseconds(0));
urls.push(responses[i].getEditResponseUrl());
}
for (var j = 1; j < data.length; j++) {
resultUrls.push([data[j][0]?urls[timestamps.indexOf(data[j][0].setMilliseconds(0))]:'']);
}
sheet.getRange(2, urlCol, resultUrls.length).setValues(resultUrls);
}
當程序員依賴於同一事件時,不會直接控制觸發函數的調用順序。
不過,根據您的情況,有幾個可用的選項。
僅對事件使用一個觸發函數,並使其按所需順序調用當前函數。 (或者,將assignEditUrls()
設置為唯一的觸發函數,並在完成任務后調用SendConfirmationMail()
。
讓SendConfirmationMail()
檢查Edit URL的可用性,如果URL還沒有准備好,請調用Utilities.sleep()
。 (循環執行,直到准備好。)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.