such a question: There is a code that sends an email with the data of the cell “var RANGE” Under the condition “var check” > 10 in the “if” function What needs to be done to:
-
The “var check” condition did not parse a single cell, but a range. (Just write Q123:Q126, it won’t work, the script is not executed) and the condition should not be >10, but equal to =10 since the trigger runs the function every day and checks the table.
-
If the number 10 is in the “var check” range, then the entire line should be sent by email. If it doesn’t work out, then at least do it like this>
-
“var RANGE” make it possible to selectively take cells (ex. B121:N129, R123:T129)
Can i get some advice?
var ID = "1sBtjJ9x4IKwb9GKu3x3DwoNWTxPej7HJWk5ze8aK"; //speadsheet id
var EMAIL = "[email protected]"; //email
var RANGE = "Warranty_2021!B121:n129"; //data range to send
var check = "Warranty_2021!Q123:Q123"; //parametr
var text = "Servis"; //subject
function sendData() {
var spreadsheet = SpreadsheetApp.openById(ID);
var data = spreadsheet.getRangeByName(RANGE).getValues();
var message = {};
if (SpreadsheetApp.openById(ID).getRangeByName(check).getValues()>10){ //condition
message.subject = "[La Test] " + text;
message.to = EMAIL;
message.htmlBody = dataToHtmlTable_(data) +
"<br><br>[IT care you ;)]";
MailApp.sendEmail(message);
}
let quota = MailApp.getRemainingDailyQuota();
console.log(quota)
}
Array.prototype.datesToString = function(){
return this.map(function(row){
return row.map(function(cell){
return cell && cell.getTime ? Utilities.formatDate(cell, Session.getScriptTimeZone(), "yyyy-MM-dd ") : cell;
});
});
}
function dataToHtmlTable_(data){
return JSON.stringify(data, null, " ")
.replace(/^[/g, "<table>")
.replace(/]$/g, "</table>")
.replace(/^ss[$/mg, "<tr>")
.replace(/^ss],{0,1}$/mg, "</tr>")
.replace(/^s{4}"{0,1}(.*?)"{0,1},{0,1}$/mg, "<td>$1</td>");
}