I wrote a script that is supposed to automatically send a list from a google sheet via email when the value of cell E7 is above 1. It works if I change the value of E7 manually. But when the data is transfered into the google sheet via an external application, it doesn't work. (I already set up a trigger) What an I doing wrong? Can anyone help me with this?
function FunzioneFE(e) {
var ss = SpreadsheetApp.getActive();
var sheet = ss.getSheetByName("Foglio2");
var Cella = sheet.getRange("E7").getValue();
{
if(Cella > 1){
{
var emailRange = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Foglio2").getRange("C2");
var emailAddress = emailRange.getValue();
var Text = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Foglio2").getRange("D2");
var typ = Text.getValue();
var aliases = GmailApp.getAliases();
Logger.log(aliases)
var ws = ss.getSheetByName("Foglio2");
var h1 = ws.getRange("D2").getValue();
var headers = ws.getRange("A1:B1").getValues();
var descr = "FoodEngel"; //headers[0][0];
const tipo = headers[0][1];
var lr = ws.getLastRow();
var tableRangeValues = ws.getRange(2,1,lr-1,2).getValues();
var htmlTemplate = HtmlService.createTemplateFromFile("email");
var file = SpreadsheetApp.getActive();
var sheet = file.getSheetByName("Foglio2");
htmlTemplate.h1 = h1;
htmlTemplate.descr = descr;
htmlTemplate.tipo = tipo;
htmlTemplate.tableRangeValues = tableRangeValues;
var htmlForEmail = htmlTemplate.evaluate().getContent();
console.log(htmlForEmail);
GmailApp.sendEmail(
emailAddress,
typ,
'Bitte Lesen.',{
htmlBody: htmlForEmail,
name: "FoodEngel",
from: aliases[0]
})};
}}}