function emailArray(){
var ss=SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName('Sheet1');
var startRow = 2;
var lastRow = sheet.getLastRow();
var lastColumn = sheet.getLastColumn();
var range = sheet.getRange(startRow,1,lastRow,lastColumn);
var data = range.getValues();
var array = [];
for(var i=0;i<data.length;++i){
var row = data[i];
var rowTemp=[];
for (var j=0; j<row.length; j++)
{
if(j==4||j==3||j==1||j==5){continue;}
rowTemp.push(row[j])
}
var emailPos = row[3];
var date = row[2];
if(emailPos =='<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="85e0fde4e8f5e9e0b1c5e2e8e4ece9abe6eae8">[email protected]</a>'&& date == 0){
array.push(rowTemp);
}
}
GmailApp.sendEmail('<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="05607d646875696034456268646c692b666a68">[email protected]</a>','This is a test',array.join('\n\n'));
}
The above script is used to send an email when the date count is 0 and the email address serves as the reference for whom to email. I am trying to format the array in table format but facing difficulties. Are there any solutions on how to achieve this? I have beginner-level expertise in scripting.
After researching various resources, here is another attempt with the following script that did not produce the desired outcome;
function arrayMail(){
var ss=SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName('Sheet1');
var startRow = 2;
var lastRow = sheet.getLastRow();
var lastColumn = sheet.getLastColumn();
var range = sheet.getRange(startRow,1,lastRow,lastColumn);
var data = range.getValues();
var tableStart = "<table border=\"1\"><tr>";
var tableEnd = "</tr></table>";
var array = [];
for(var i=0;i<data.length;++i){
var row = data[i];
var rowTemp=[];
for (var j=0; j<row.length; j++)
{
if(j==4||j==3||j==1||j==5){continue;}
rowTemp.push('<td>'+row[j]+'</td>');
}
var emailPos = row[3];
var date = row[2];
if(emailPos =='<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0e6b766f637e626b3a4e69636f6762206d6163">[email protected]</a>'&& date == 0){
array.push(rowTemp);
}
}
var HTMLbody = tableStart +array.join('')+tableEnd;
GmailApp.sendEmail('<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="91f4e9f0fce1fdf4d1f6fcf0f8fdbff2fefc">[email protected]</a>','This is a test',HTMLbody,{htmlBody:HTMLbody});
}
The current result does not match the expected format;
Desired output formatting should be like the following example:
Infusion Pump 0
Infusion Pump 0