admin管理员组文章数量:1431904
The code is pretty much done but I want to include today's date in the subject. What do I have to add to "const subject" in order to accomplish this? I've already defined today's date as "today"
the code is in the image, please see the highlighted part
See image code
function sendEmails() {
const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
const dataRange = sheet.getRange("A17:dm");
const data = dataRange.getValues();
i=0; //i & j is the row number (up/down)
j=3;
const col = data[j];
const row = data[i];
const machinetype = row[84]; //the 84 is how far you are going to the right, add 4 to each when re-running it
const machinemodel = col[84];
const emailAddress = "[email protected]";
const subject = "New Machine";
const message = createEmailMessage(machinetype, machinemodel);
function createEmailMessage(machinetype, machinemodel) {
const message = `Hi Dhariana,
A new machine has arrived at the shop. It is a ${machinemodel}... a ${machinetype} machine.
Kindly schedule the cleaning procedure.
Thank you.
Best,
`;
return message;
}
try {
MailApp.sendEmail(emailAddress, subject, message);
console.log(` Email sent to ${emailAddress}`);
console.log(`${machinetype}, ${machinemodel}`);
} catch (error) {
}
}
The code is pretty much done but I want to include today's date in the subject. What do I have to add to "const subject" in order to accomplish this? I've already defined today's date as "today"
the code is in the image, please see the highlighted part
See image code
function sendEmails() {
const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
const dataRange = sheet.getRange("A17:dm");
const data = dataRange.getValues();
i=0; //i & j is the row number (up/down)
j=3;
const col = data[j];
const row = data[i];
const machinetype = row[84]; //the 84 is how far you are going to the right, add 4 to each when re-running it
const machinemodel = col[84];
const emailAddress = "[email protected]";
const subject = "New Machine";
const message = createEmailMessage(machinetype, machinemodel);
function createEmailMessage(machinetype, machinemodel) {
const message = `Hi Dhariana,
A new machine has arrived at the shop. It is a ${machinemodel}... a ${machinetype} machine.
Kindly schedule the cleaning procedure.
Thank you.
Best,
`;
return message;
}
try {
MailApp.sendEmail(emailAddress, subject, message);
console.log(` Email sent to ${emailAddress}`);
console.log(`${machinetype}, ${machinemodel}`);
} catch (error) {
}
}
Share
Improve this question
edited Nov 19, 2024 at 13:37
Wicket
38.8k9 gold badges80 silver badges195 bronze badges
asked Nov 19, 2024 at 6:34
Miguel Arturo MonclusMiguel Arturo Monclus
11 silver badge
1 Answer
Reset to default 1Append new Date to a string
Since your today
variable is already a string because of Utilities.formatDate() (see image below) you can just easily append it to a string(your subject) using the following ways:
Using +
symbol
const subject = "New machine "+today
or
Using String literals
const subject = `New Machine ${today}`
Data type of today
variable
Sample Output
Reference: Utilities.formatDate
本文标签:
版权声明:本文标题:google sheets - How to show a String + today's date in a the email subject using Mailapp.sendemail in Apps Script? - Sta 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745583463a2664755.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论