Hi! I’m new in this forum.
I was able to send rows from a Google Sheet via e-mail, using the Javascript sendEmail() function. The aforementioned Google Sheet is linked to a Google Form.
In the sheet, under the column "Recursive_Requests ", there are 2 options to send data. I would want that:
- if you select "send_every_day " option, the request is sent by e-mail every day;
- if you select "send_every_monday ", the request remains in the sheet, BUT it is sent only every Monday;
- if you select "No ", no changes are made.
Any help would be appreciated!
Code used:
function sendEmail() {
var orderData = getData();
var body = getEmailText(orderData);
MailApp.sendEmail({
to: "email@example.com",
cc: "anotheremail@example.com",
subject: "Today's orders",
body: body
});
}
function getEmailText(orderData) {
var text = "";
orderData.forEach(function(order) {
text = text + order.department + "\n" + order.request + "\n-----------------------\n\n";
});
return text;
}
/**
* @OnlyCurrentDoc
*/
function getData() {
var values = SpreadsheetApp.getActive().getSheetByName("Form responses 1").getRange("Orders_NamedRange").getValues();
values.shift();
var orders = [];
values.forEach(function(value) {
var order = {};
order.department = value[1];
order.request = value[2];
orders.push(order);
})
//Logger.log(JSON.stringify(stocks));
return orders;
}
My Google Form → click here
My Google Sheet → click here