使用包含单元格值的body / subject的电子邮件通知 [英] Email notifications with body/subject containing cell value
问题描述
我想使用事件触发器创建Google表格。我正在使用Google Apps脚本。
I would like to create a Google Sheets with event triggers. I'm using Google Apps Script.
当单元格的值为 Ok
时,将发送一条邮件以发出警告一个同事(验证)。
When a cell has value Ok
, a mail would be sent to warn a colleague (validation).
我发现一个脚本,它的工作原理。
I found a script and it works.
现在我想要邮件身体和邮件需要包含触发单元格的值 OK
的行的单元格值。
Now I would like the mail body and mail subject to include cell values of the row where the trigger cell has the value OK
.
这里是这个工作表的一个例子:
Here is an example of the sheet:
当我在K8中写Ok时,会向同事发送一封邮件。我希望身体邮件包含F8,G8和J8中的信息。同样,如果我在K7中写Ok,我希望发送的邮件包含F7,G7和J7的信息。
(示例:您的请求已被验证,必要性为5级所需数量为1.价格为17,94€)
When I write "Ok"in K8, a mail is sent to a colleague. And I would like the body mail to contain information in F8, G8, and J8. Likewise, if I write "Ok" in K7, I would like the sent mail to contain info from F7, G7, and J7. (Example: "Your request has been validated. Necessity is level 5. Quantity needed is 1. Price is 17,94€.")
脚本我正在使用:
/**
* add trigger for onedit -
* see menu -> Resouces -> Current project's triggers
*/
function Initialize() {
var triggers = ScriptApp.getProjectTriggers();
for(var i in triggers) {
ScriptApp.deleteTrigger(triggers[i]);
}
ScriptApp.newTrigger("sendNotification")
.forSpreadsheet(SpreadsheetApp.getActiveSpreadsheet())
.onEdit()
.create();
};
/**
*
*/
function sendNotification(e) {
if("K" == e.range.getA1Notation().charAt(0)) {
if(e.value == "ok") {
//Define Notification Details
var recipients = "user@example.com";
var subject = "Validation" ;
var body = "Achat valider, à procéder";
//Send the Email
MailApp.sendEmail(recipients, subject, body);
}
}
}
code> subject 和Var Body
包含单元格值
How do I get Var subject
and Var Body
to contain cell values?
推荐答案
问题解决。
要求修改,当您想要更改电池值时的电子邮件通知,并希望邮件包含单元格值您编辑的同一行:
To summurize, when you want Email notification when cell value is changed and you want the mail to contain cells value from the same row you've edited :
/**
* add trigger for onedit -
* see menu -> Resouces -> Current project's triggers
*/
function Initialize() {
var triggers = ScriptApp.getProjectTriggers();
for(var i in triggers) {
ScriptApp.deleteTrigger(triggers[i]);
}
ScriptApp.newTrigger("sendNotification")
.forSpreadsheet(SpreadsheetApp.getActiveSpreadsheet())
.onEdit()
.create();
};
/**
*
*/
function sendNotification(e) {
if("L" == e.range.getA1Notation().charAt(0)) {
if(e.value == "oui") {
//Define Notification Details
var recipients = "XX@sCC.net";
var subject = "Request" + " - N° " + e.source.getRange('A'+ e.range.getRow()).getValue() ;
var body = "lolcat : " + e.source.getRange('B'+ e.range.getRow()).getValue() ;
//Send the Email
MailApp.sendEmail(recipients, subject, body);
}
}
}
为我工作正常感谢您的帮助:)
Working fine for me. Thank you for the help :)
这篇关于使用包含单元格值的body / subject的电子邮件通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!