我正在尝试编写一个脚本,根据某人是否提交新回复或编辑现有回复来发送特定电子邮件。我需要阅读主题行"名字姓氏:编辑"或"名字姓氏:回应"取决于提交的内容。如果有人编辑了他们的回复,则只有已更改的值会显示在电子邮件中;但是,如果他们不改变名称,它就不会出现在主题行中。有关如何更改此设置的任何想法,以便每次有编辑或响应时都会显示其名称? 提前谢谢!
function Initialize() {
try {
var triggers = ScriptApp.getProjectTriggers();
for (var i in triggers)
ScriptApp.deleteTrigger(triggers[i]);
ScriptApp.newTrigger("formSubmitted")
.forSpreadsheet(SpreadsheetApp.getActiveSpreadsheet())
.onFormSubmit().create();
} catch (error) {
throw new Error("Please add this code in the Google Spreadsheet");
}
}
function formSubmitted(e) {
if (!e) {
throw new Error("Please go the Run menu and choose Initialize");
}
try {
if (MailApp.getRemainingDailyQuota() > 0) {
// You may replace this with another email address
var email = "my email";
// Enter your subject for Google Form email notifications
var key, entry,
ss = SpreadsheetApp.getActiveSheet(),
cols = ss.getRange(1, 1, 1, ss.getLastColumn()).getValues()[0],
message = "",
first = e.values[1],
last = e.values[2];
var editSubject = first + " " + last +": Edit";
var submitSubject = first + " " + last + ": Submitted";
// Iterate through the Form Fields
for (var keys in cols) {
key = cols[keys];
entry = e.namedValues[key] ? e.namedValues[key].toString() : "";
// Only include form fields that are not blank
if ((entry !== "") && (entry.replace(/,/g, "") !== ""))
message += key + ' :: ' + entry + "\n\n";
}
}
if (e.range.getNotes()[0].join('')) {
MailApp.sendEmail(email, editSubject, message);
}
else {
MailApp.sendEmail(email, submitSubject, message);
}
}
catch (error) {
Logger.log(error.toString());
}
}
答案 0 :(得分:0)
您可能需要检查使用documentation的triggers,以便在用户回复表单时发送电子邮件。
样品申请:
/**
* Adjust the onFormSubmit trigger based on user's requests.
*/
function adjustFormSubmitTrigger() {
var form = FormApp.getActiveForm();
var triggers = ScriptApp.getUserTriggers(form);
var settings = PropertiesService.getDocumentProperties();
var triggerNeeded =
settings.getProperty('creatorNotify') == 'true' ||
settings.getProperty('respondentNotify') == 'true';