I have a cell column that auto-populates every morning with a list of product names. I want to schedule an appscript to run every morning containing those names, either as a table or as a list. This is the script I have so far.
function myFunction(e) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet1 = ss.getSheetByName('For Ordering');
var data = sheet1.getRange("A1:A50");
var email = "[email protected]"
MailApp.sendEmail(email,"For Ordering","These are the things you need to order today " + data + " Thank you");
}
I’ve tried using getvalues and getdatatable as well but they just return the former doesn’t work and the latter just returns the word “datatable” in place of data in the email. Right now the script below just says “range” in place of data when the email is sent. What am I doing wrong?
kimmandy36 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Use Range.getValues()
or Range.getDisplayValues()
as appropriate, like this:
function myFunction(e) {
const ss = SpreadsheetApp.getActive();
const data = ss.getRange('For Ordering!A1:A50')
.getDisplayValues()
.join(', ');
const emailAddress = '[email protected]';
MailApp.sendEmail(emailAddress, 'For Ordering', `These are the things you need to order today:nn${data}nnThank you.`);
ss.toast('Mail sent.');
}
See Range.getDisplayValues().