I would like help with iterating over a javascript object where each key:value pair is written on a new line in an email body using Appscript so I think it needs to be converted to a HTML string, but I am unsure. The code I have is below.
let dictionary = {}
const gratitude = dataRange.filter(function(row) {
return row[0] >= result && row[10] != 'Gratitude' && row[10] != 'Notes' && row[10] != ''
}).map(function(row) {
return dictionary[row[0]] = row[10]
})
var message = {
to: 'person1@gmail.com',
subject: 'Weekly Summary',
body:
`
This week you completed:
${dictionary}`,
}
MailApp.sendEmail(message);
Any help would be great.
Thank you!
Perhaps it would be easier to use an array that can readily be converted to a text string with .join(). Try this:
const body = dataRange
.filter(row => row[0] >= result && row[10] !== 'Gratitude' && row[10] !== 'Notes' && row[10] !== '')
.map(row => [row[0], row[10]].join(': '))
.join('\n');
const message = {
to: 'person1@gmail.com',
subject: 'Weekly Summary',
body: 'This week you completed:\n\n' + body,
};
MailApp.sendEmail(message);