Google Sheets: Automated email when cell value is less than another - email

I am trying to make an inventory sheet where an automated email will be sent out when the inventory falls below a specific limit. I have set it so B2 is < C2, but I am not getting an email.
function sendEmailAlert() {
var sheet = SpreadsheetApp.getActiveSpreadsheet();
var rangeA = sheet.getRange('A2:A8');
var item = rangeA.getValues();
var rangeB = sheet.getRange('B2:B8');
var inventory = rangeB.getValues();
var rangeC = sheet.getRange('C2:C8');
var limit = rangeC.getValues();
var toEmail = 'XX#XX.com';
var subject = 'Inventory to Order';
var body = 'Item:' + item + 'needs to be ordered';
for (i in item){
if(inventory <= limit ) {
MailApp.sendEmail(toEmail,subject, body);
}
}
}

Try this:
function sendEmailAlert() {
var sheet=SpreadsheetApp.getActiveSpreadsheet();
var rangeA=sheet.getRange('A2:A8');
var item=rangeA.getValues();
var rangeB=sheet.getRange('B2:B8');
var inventory=rangeB.getValues();
var rangeC=sheet.getRange('C2:C8');
var limit=rangeC.getValues();
var toEmail='XX#XX.com';
var subject='Inventory to Order';
for (var i=0;i<item.length;i++){
if(inventory[i][0]<=limit[i][0]) {
var body='Item:' + item[i][0] + 'needs to be ordered';
MailApp.sendEmail(toEmail,subject, body);
}
}
}
You could also add something like this if you want to avoid sending duplicates
function sendEmailAlert() {
var sheet=SpreadsheetApp.getActiveSpreadsheet();
var rangeA=sheet.getRange('A2:A8');
var item=rangeA.getValues();
var rangeB=sheet.getRange('B2:B8');
var inventory=rangeB.getValues();
var rangeC=sheet.getRange('C2:C8');
var limit=rangeC.getValues();
var rangeD=sheet.getRange('D2:D8');
var sent=rangeD.getValues();
var toEmail='XX#XX.com';
var subject='Inventory to Order';
for (var i=0;i<item.length;i++){
if(inventory[i][0]<=limit[i][0] && sent[i][0]!="sent") {
var body='Item:' + item[i][0] + 'needs to be ordered';
MailApp.sendEmail(toEmail,subject, body);
sent[i][0]="sent";
}
}
rangeD.setValues(sent);
}

Related

Error in Google Earth Engine: Computed value is too large

I'm trying to achieve classification for image collection over 30 years as the code shows below:
var roi = ee.FeatureCollection("users/471033961/YellowRiver");
var empty = ee.Image().toByte();
var outline = empty.paint({
featureCollection:roi,
color:0,
width:3
});
Map.addLayer(outline, {palette: "ff0000"}, "outline");
//////////////////////////////landsat 5,7
function l57class(year){
var startDate = ee.Date.fromYMD(year, 1, 1);
var endDate = ee.Date.fromYMD(year+1, 1, 1);
var LC57_BANDS = ['B1', 'B2', 'B3', 'B4', 'B5', 'B7']; //Landsat57
var STD_NAMES = ['B2', 'B3', 'B4', 'B5', 'B6', 'B7'];
var cloudMaskL457 = function(image) {
var qa = image.select('pixel_qa');
// If the cloud bit (5) is set and the cloud confidence (7) is high
// or the cloud shadow bit is set (3), then it's a bad pixel.
var cloud = qa.bitwiseAnd(1 << 5)
.and(qa.bitwiseAnd(1 << 7))
.or(qa.bitwiseAnd(1 << 3));
// Remove edge pixels that don't occur in all bands
var mask2 = image.mask().reduce(ee.Reducer.min());
return image.updateMask(cloud.not()).updateMask(mask2);
}
var collection1 = ee.ImageCollection("LANDSAT/LE07/C01/T1_SR")
.filterDate(startDate, endDate)
.filterBounds(roi)
.filter(ee.Filter.lte('CLOUD_COVER',10))
.map(cloudMaskL457)
var collection2 = ee.ImageCollection("LANDSAT/LT05/C01/T1_SR")
.filterDate(startDate, endDate)
.filterBounds(roi)
.filter(ee.Filter.lte('CLOUD_COVER',10))
.map(cloudMaskL457)
var collection = collection1.merge(collection2).select(LC57_BANDS, STD_NAMES)
var image=collection.mosaic().clip(roi)
function NDWI(img){
var nir = img.select('B4');
var green = img.select('B2');
var ndwi = img.expression(
'(B3-B5)/(B3+B5)',
{
'B5':nir,
'B3':green
});
return ndwi;
}
function EWI(img){
var swir1 = img.select('B6')
var nir = img.select('B5');
var green = img.select('B3');
var ewi = img.expression(
'(B3-B5-B6)/(B3+B5+B6)',
{
'B6':swir1,
'B5':nir,
'B3':green
});
return ewi;
}
var MNDWI = image.normalizedDifference(['B3', 'B6']).rename('MNDWI');
var ndbi = image.normalizedDifference(['B6', 'B5']).rename('NDBI');
var ndvi = image.normalizedDifference(['B5', 'B4']).rename('NDVI');
var ewi = EWI(image).rename('EWI');
var ndwi = NDWI(image).rename('NDWI');
var lswi = image.normalizedDifference(['B5','B6']).rename('LSWI')
var nbr2 = image.normalizedDifference(["B6", "B7"]).rename("NBR2")
var awei = image.expression(
'4*(green-SWIR1)-(0.25*NIR+2.75*SWIR2)',{
green:image.select('B3'),
NIR:image.select('B5'),
SWIR1:image.select('B6'),
SWIR2:image.select('B7'),
}).float().rename('AWEI')
image=image
.addBands(ndvi)
.addBands(ndbi)
.addBands(MNDWI)
.addBands(ndwi)
.addBands(ewi)
.addBands(lswi)
.addBands(awei)
.addBands(nbr2)
var classNames = city.merge(water).merge(tree).merge(crop).merge(bare);
var bands = ['B2', 'B3', 'B4', 'B5', 'B6', 'B7','MNDWI','NDBI','NDVI','EWI','NDWI','AWEI','LSWI',"NBR2"];
var training = image.select(bands).sampleRegions({
collection: classNames,
properties: ['landcover'],
scale: 30
});
var withRandom = training.randomColumn('random');
var split = 0.8;
var trainingPartition = withRandom.filter(ee.Filter.lt('random', split));
var testingPartition = withRandom.filter(ee.Filter.gte('random', split));
var classProperty = 'landcover';
var classifier = ee.Classifier.smileRandomForest(100).train({
features: trainingPartition,
classProperty: 'landcover',
inputProperties: bands
});
var classified = image.select(bands).classify(classifier);
var test = testingPartition.classify(classifier);
var confusionMatrix = test.errorMatrix('landcover', 'classification');
print(year)
print('confusionMatrix',confusionMatrix);
print('overall accuracy', confusionMatrix.accuracy());
print('kappa accuracy', confusionMatrix.kappa());
Map.addLayer(classified,{}, "classified"+year);
Export.image.toDrive({
image: classified,
description: 'YR_cart'+year,
folder: 'YR_cart'+year,
scale: 30,
region: roi,
maxPixels:34e10
});
}
////////////////////////////////////////////////////////////////////////////////
function l8class(year){
var startDate = ee.Date.fromYMD(year, 1, 1);
var endDate = ee.Date.fromYMD(year+1, 1, 1);
var collection = ee.ImageCollection("LANDSAT/LC08/C01/T1_RT")
.filterDate(startDate, endDate)
.filterBounds(roi)
.filter(ee.Filter.lte('CLOUD_COVER',20))
var remove_cloud=function(collection)
{
var fun_calCloudScore = function(image) {
return ee.Algorithms.Landsat.simpleCloudScore(ee.Image(image));
};
var calCloudScore = ee.ImageCollection(collection)
.map(fun_calCloudScore)
;
var fun_maskCloud = function(image) {
var mask = image.select(['cloud']).lte(10);
return image.updateMask(mask);
};
var vsParam={band:['B2', 'B3', 'B4', 'B5', 'B6', 'B7'],min:0,max:0.3};
var maskCloud = ee.ImageCollection(calCloudScore)
.map(fun_maskCloud) ;
var maskCloud2=maskCloud.mean()
return maskCloud;
}
var image=remove_cloud(collection).mosaic().clip(roi);
function NDWI(img){
var nir = img.select('B4');
var green = img.select('B2');
var ndwi = img.expression(
'(B3-B5)/(B3+B5)',
{
'B5':nir,
'B3':green
});
return ndwi;
}
function EWI(img){
var swir1 = img.select('B6')
var nir = img.select('B5');
var green = img.select('B3');
var ewi = img.expression(
'(B3-B5-B6)/(B3+B5+B6)',
{
'B6':swir1,
'B5':nir,
'B3':green
});
return ewi;
}
var MNDWI = image.normalizedDifference(['B3', 'B6']).rename('MNDWI');
var ndbi = image.normalizedDifference(['B6', 'B5']).rename('NDBI');
var ndvi = image.normalizedDifference(['B5', 'B4']).rename('NDVI');
var ewi = EWI(image).rename('EWI');
var ndwi = NDWI(image).rename('NDWI');
var lswi = image.normalizedDifference(['B5','B6']).rename('LSWI')
var nbr2 = image.normalizedDifference(["B6", "B7"]).rename("NBR2")
var awei = image.expression(
'4*(green-SWIR1)-(0.25*NIR+2.75*SWIR2)',{
green:image.select('B3'),
NIR:image.select('B5'),
SWIR1:image.select('B6'),
SWIR2:image.select('B7'),
}).float().rename('AWEI')
image=image
.addBands(ndvi)
.addBands(ndbi)
.addBands(MNDWI)
.addBands(ndwi)
.addBands(ewi)
.addBands(lswi)
.addBands(awei)
.addBands(nbr2)
var classNames = city.merge(water).merge(tree).merge(crop).merge(bare);
var bands = ['B2', 'B3', 'B4', 'B5', 'B6', 'B7','MNDWI','NDBI','NDVI','EWI','NDWI','AWEI','LSWI',"NBR2"];
var training = image.select(bands).sampleRegions({
collection: classNames,
properties: ['landcover'],
scale: 30
});
var withRandom = training.randomColumn('random');
var split = 0.9;
var trainingPartition = withRandom.filter(ee.Filter.lt('random', split));
var testingPartition = withRandom.filter(ee.Filter.gte('random', split));
var classProperty = 'landcover';
var classifier = ee.Classifier.libsvm().train({
features: trainingPartition,
classProperty: 'landcover',
inputProperties: bands
});
var classified = image.select(bands).classify(classifier);
var test = testingPartition.classify(classifier);
var confusionMatrix = test.errorMatrix('landcover', 'classification');
print(year)
print('confusionMatrix',confusionMatrix);
print('overall accuracy', confusionMatrix.accuracy());
print('kappa accuracy', confusionMatrix.kappa());
Map.addLayer(classified,{}, "classified"+year);
Export.image.toDrive({
image: classified,
description: 'YR_cart'+year,
folder: 'YR_cart'+year,
scale: 30,
region: roi,
maxPixels:34e10
});
}
function main() {
var startYear = 2022;
var endYear = 2022;
for (var year=startYear; year<=endYear; year++) {
if (year >2012){l8class(year)}else{l57class(year)}
}
}
main();
I knew the study area was too big which lead to an error: "computed value is too large". Does anyone know how to solve this problem? better to revise based on this code if so.
Really appreciate it in advance!
To be honest I checked too many ideas but one of the effective ways I thought is to "break your study area into a bunch of tiles to calculate first, then combine all the results to get the final. However, It's just initial thinking that I didn't test.
Here is the link(you can ignore the comment in Chinese): https://code.earthengine.google.com/5d362229b959d96b9e4017571ba11a75

BCC doesn't seem to function as an option of sendEmail - name and replyTo work though

function myFunction() {
var ss = SpreadsheetApp.getActive();
var sheet = ss.getSheetByName("Welcome");
var targetSheet = ss.getSheetByName("Done");
var startRow = 2;
var lr = sheet.getLastRow();
var dataRange = sheet.getRange(startRow, 1, lr-1, 6);
var data = dataRange.getValues();
var colNumber = sheet.getLastColumn()-1;
var delRows = [];
for (var i = 0; i < data.length; i++) {
var row = data[i];
var id = row[0];
var emailAddress = row[1];
var date = row[2];
var city = row[3];
var bccmail = row[6];
var Sender = 'XXXXXX';
var reply = 'xxxxxx#xxxxxxx.com';
if (emailAddress.match('#') === null){
continue;
};
var subject = row[4];
var message = "Hey " + id + ", welcome in the team " + row[5];
MailApp.sendEmail(emailAddress, subject, message, {bcc: bccmail,name: Sender,replyTo: reply});
var targetRange = targetSheet.getRange(targetSheet.getLastRow()+1, 1, 1, colNumber);
var sourceRange = sheet.getRange(i+startRow, 1, 1, colNumber);
sourceRange.copyTo(targetRange);
delRows.push(i+startRow);
}
delRows.reverse().forEach(ri=>{sheet.deleteRow(ri)});
Almost all the script works fine. When it comes to sendEmail, I have tried to follow these guidelines and use sendEmail(recipient, subject, body, options). 2 out of 3 options work fine but BCC doesn't work at the moment. Do you know what I am doing wrong? Can BCC be a variable?
The problem is in this line:
var bccmail = row[6];
dataRange is defined as a range with only 6 columns. data is a 2D array with the values of dataRange. row is a 1D array with a single row of data. JavaScript array indexes only start at 0, so the values are in row[0] to row[5].
Please check your sheet in which column does the bcc string is defined and count the index from 0.
Reference:
Arrays in JavaScript

I'm trying to send an automated anniversary list. my code returns no errors but is sending no emails

function sendAnniversaryCampaing(){
var ss = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/1FkKtSpvwecDEc6of2Nh37ud3qGgcNaK253S7jd7KqB0/edit#gid=0");// Sheet Url
var sheet = ss.getSheetByName("Sheet1");// Make Sure Sheet name matches at the bottom
var templateId = '157YoH_ngoESR-pwNUXfFj0dUwDYXBqOd6RCgB_cJVsQ';// the template doc with placeholders
var cDate = new Date(); //Present Day,
for(var i =2 ;i<=sheet.getLastRow(); i++){
var anDate = sheet.getRange(i,4).getValue(); // Date from SpreadSheet
if(cDate.getDate()==anDate.getDate()){
if(cDate.getMonth()==anDate.getMonth()){
var name = sheet.getRange(i,2).getValue();
var toMail= sheet.getRange(i,3).getValue();
sendMail(sheet,templateId,name,toMail);//sheet doesn't appear to be used in sendMail() Edited by Cooper.
sheet.getRange(i,5).setValue("Anniversary email sent");
}
}
}
}
function sendMail(sheet,templateId,name,toMail){
var docId = DriveApp.getFileById(templateId).makeCopy('temp').getId();
var doc = DocumentApp.openById(docId);// the temp copy
var body = doc.getBody();
body.replaceText('#name#',name);// update the temp doc
doc.saveAndClose();// save changes before conversion
var url = "https://docs.google.com/feeds/download/documents/export/Export?id="+docId+"&exportFormat=html";
var param = {
method : "get",
headers : {"Authorization": "Bearer" + ScriptApp.getOAuthToken()}
};
var htmlBody = UrlFetchApp.fetch(url,param).getContentText();
var trashed = DriveApp.getFileById(docId).setTrashed(true);// delete temp copy
MailApp.sendEmail(toMail,'Anniversary Campaing'+name,' ' ,{htmlBody : htmlBody});// send to myself to test
}
Try this:
function sendAnniversaryCampaing(){
var ss = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/1FkKtSpvwecDEc6of2Nh37ud3qGgcNaK253S7jd7KqB0/edit#gid=0");// Sheet Url
var sheet = ss.getSheetByName("Sheet1");// Make Sure Sheet name matches at the bottom
var templateId = '157YoH_ngoESR-pwNUXfFj0dUwDYXBqOd6RCgB_cJVsQ';// the template doc with placeholders
var cDate = new Date().valueOf(); //Present Day,
for(var i=2;i<=sheet.getLastRow(); i++){
var anDate=new Date(sheet.getRange(i,4).getValue()).valueOf(); // Date from SpreadSheet
if(cDate==anDate){
var name=sheet.getRange(i,2).getValue();
var toMail= sheet.getRange(i,3).getValue();
sendMail(sheet,templateId,name,toMail);
sheet.getRange(i,5).setValue("Anniversary email sent");
}
}
}

Google Sheet sends email from list when cell condition met

I'm still very new to scripting and can't work out why the below script doesn't work
function sendReturnEmail(event) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var row = sheet.getActiveRange().getRow();
var cellvalue = ss.getActiveCell().getValue().toString();
if(event.range.getA1Notation().indexOf("K") && sheet.getRange("K" + row).getDisplayValue() == "Approved")
{
var rowVals = getActiveRowValues(sheet);
var aliases = GmailApp.getAliases();
var to = rowVals.user;
var subject = "Allocation request approved";
var body = "Your allocation request of " +rowVals.quantity + " cases on " + rowVals.date + " from " + rowVals.depot + " has been approved. <br \> <br \>"
+ "Regards, <br \> <br \>" +rowVals.analyst + "<br \> CPF Team";
Logger.log(aliases);
GmailApp.sendEmail(to,subject,body,
{from: aliases[0]})
;
}}
function getActiveRowValues(sheet){
var cellRow = sheet.getActiveRange().getRow();
// get depot value
var depotCell = sheet.getRange("E" + cellRow);
var depot = depotCell.getDisplayValue();
// get date value
var dateCell = sheet.getRange("F" + cellRow);
var date = dateCell.getDisplayValue();
// get quantity value
var quantCell = sheet.getRange("G" + cellRow);
var quant = quantCell.getDisplayValue();
// return an object with your values
var analystCell = sheet.getRange("J" + cellRow);
var analyst = analystCell.getDisplayValue();
var userCell = sheet.getRange("O" + cellRow);
var user = userCell.getDisplayValue();
return {
depot: depot,
date: date,
quantity: quant,
analyst: analyst,
user: user
} }
}
The sheet is question has several scripts running in it, one of them being this:
function onEdit() {
var s = SpreadsheetApp.getActiveSheet();
if( s.getName() == "Allocation Requests" ) { //checks that we're on the correct sheet
var r = s.getActiveCell();
if( r.getColumn() == 2) { //checks the column
var nextCell = r.offset(0, 13);
nextCell.setValue(Session.getEffectiveUser());
}
}
I now want the sheet to send an email to the email address captured using the above script (which works fine) when the corresponding cell in column K is manually changed to "Approved."
Can anyone see what I'm doing wrong. I get no errors when it runs, but I'm not getting an email. I've searched other questions but none have helped. Many thanks in advance.

Email address selector in Google Apps script

I have a script to select an email address depending on the result of a dropdown selector on a form which is working as intended.
But I have another dropdown which if "08-Maintenance" is selected I want it to override the email selector. This bit doesn't work. Any help greatly appreciated.
//select THIS spreadsheet
var LogSheet = SpreadsheetApp.getActiveSpreadsheet();
//select correct worksheet
var sheet = LogSheet.getSheetByName("LOG");
//declare the row to look at (the last row)
var lastRowNumber = sheet.getDataRange().getNumRows();
//declare and obtain the variable for the Source Code in column 3
var SourceValue = sheet.getRange(lastRowNumber, 3).getValue();
//declare and obtain the variable for the Location Code in column 4
var LocationValue = sheet.getRange(lastRowNumber,4).getValue();
//declare and obtain the variable for the Hazard being reported in column 6
var HazardValue = sheet.getRange(lastRowNumber,6).getValue();
//declare the correct email addresses to use
var email01 = LogSheet.getSheetByName("LocationCodes").getRange(3, 5).getValue();
var email02 = LogSheet.getSheetByName("LocationCodes").getRange(4, 5).getValue();
var email03 = LogSheet.getSheetByName("LocationCodes").getRange(5, 5).getValue();
var email04 = LogSheet.getSheetByName("LocationCodes").getRange(6, 5).getValue();
var email05 = LogSheet.getSheetByName("LocationCodes").getRange(7, 5).getValue();
var email06 = LogSheet.getSheetByName("LocationCodes").getRange(8, 5).getValue();
var email07 = LogSheet.getSheetByName("LocationCodes").getRange(9, 5).getValue();
var email08 = LogSheet.getSheetByName("LocationCodes").getRange(10, 5).getValue();
var email09 = LogSheet.getSheetByName("LocationCodes").getRange(11, 5).getValue();
var email10 = LogSheet.getSheetByName("LocationCodes").getRange(12, 5).getValue();
var email11 = LogSheet.getSheetByName("LocationCodes").getRange(13, 5).getValue();
var email12 = LogSheet.getSheetByName("LocationCodes").getRange(14, 5).getValue();
var email13 = LogSheet.getSheetByName("LocationCodes").getRange(15, 5).getValue();
var email14 = LogSheet.getSheetByName("LocationCodes").getRange(16, 5).getValue();
var email15 = LogSheet.getSheetByName("LocationCodes").getRange(17, 5).getValue();
var email16 = LogSheet.getSheetByName("LocationCodes").getRange(18, 5).getValue();
var email17 = LogSheet.getSheetByName("LocationCodes").getRange(19, 5).getValue();
var email18 = LogSheet.getSheetByName("LocationCodes").getRange(20, 5).getValue();
var email19 = LogSheet.getSheetByName("LocationCodes").getRange(21, 5).getValue();
var email20 = LogSheet.getSheetByName("LocationCodes").getRange(22, 5).getValue();
//declare the correct LocationCodes to check
var depot01 = LogSheet.getSheetByName("LocationCodes").getRange(3, 4).getValue();
var depot02 = LogSheet.getSheetByName("LocationCodes").getRange(4, 4).getValue();
var depot03 = LogSheet.getSheetByName("LocationCodes").getRange(5, 4).getValue();
var depot04 = LogSheet.getSheetByName("LocationCodes").getRange(6, 4).getValue();
var depot05 = LogSheet.getSheetByName("LocationCodes").getRange(7, 4).getValue();
var depot06 = LogSheet.getSheetByName("LocationCodes").getRange(8, 4).getValue();
var depot07 = LogSheet.getSheetByName("LocationCodes").getRange(9, 4).getValue();
var depot08 = LogSheet.getSheetByName("LocationCodes").getRange(10, 4).getValue();
var depot09 = LogSheet.getSheetByName("LocationCodes").getRange(11, 4).getValue();
var depot10 = LogSheet.getSheetByName("LocationCodes").getRange(12, 4).getValue();
var depot11 = LogSheet.getSheetByName("LocationCodes").getRange(13, 4).getValue();
var depot12 = LogSheet.getSheetByName("LocationCodes").getRange(14, 4).getValue();
var depot13 = LogSheet.getSheetByName("LocationCodes").getRange(15, 4).getValue();
var depot14 = LogSheet.getSheetByName("LocationCodes").getRange(16, 4).getValue();
var depot15 = LogSheet.getSheetByName("LocationCodes").getRange(17, 4).getValue();
var depot16 = LogSheet.getSheetByName("LocationCodes").getRange(18, 4).getValue();
var depot17 = LogSheet.getSheetByName("LocationCodes").getRange(19, 4).getValue();
var depot18 = LogSheet.getSheetByName("LocationCodes").getRange(20, 4).getValue();
var depot19 = LogSheet.getSheetByName("LocationCodes").getRange(21, 4).getValue();
var depot20 = LogSheet.getSheetByName("LocationCodes").getRange(22, 4).getValue();
//send the email to the 'recipient'
//if SourceValue is recorded as 08 - Mantenance Request System, the recipient is engineering.support#websiteaddress
//otherwise check location code and send to corresponding H&S Co-ordinator's email address
if (SourceValue == "08 - Mantenance Request System") {
var recipient = "engineering.support#websiteaddress";
//Start with first depot in list
} else if (LocationValue == depot01) {
var recipient = email01;
} else if (LocationValue == depot02) {
var recipient = email02;
} else if (LocationValue == depot03) {
var recipient = email03;
} else if (LocationValue == depot04) {
var recipient = email04;
} else if (LocationValue == depot05) {
var recipient = email05;
} else if (LocationValue == depot06) {
var recipient = email06;
} else if (LocationValue == depot07) {
var recipient = email07;
} else if (LocationValue == depot08) {
var recipient = email08;
} else if (LocationValue == depot09) {
var recipient = email09;
} else if (LocationValue == depot10) {
var recipient = email10;
} else if (LocationValue == depot11) {
var recipient = email11;
} else if (LocationValue == depot12) {
var recipient = email12;
} else if (LocationValue == depot13) {
var recipient = email13;
} else if (LocationValue == depot14) {
var recipient = email14;
} else if (LocationValue == depot15) {
var recipient = email15;
} else if (LocationValue == depot16) {
var recipient = email16;
} else if (LocationValue == depot17) {
var recipient = email17;
} else if (LocationValue == depot18) {
var recipient = email18;
} else if (LocationValue == depot19) {
var recipient = email19;
} else if (LocationValue == depot20) {
var recipient = email20;
} else {
//and send to Engineering Support if there is no code as a catch all.
var recipient = "engineering.support#websiteaddress"; //CHANGE TO ENG SUPP
}
//with the 'LocationCode' & 'SourceCode' as the subject
var subject = SourceValue ;
//then write the'body' of the email including the link to see the changes
var body = 'A new [' + SourceValue + '] log entry has been recorded at [' + LocationValue + '], listed as [' + HazardValue + '], please click the link > > http://goo.gl/shortcode < < to view details.';
{
//then send the email
MailApp.sendEmail(recipient,subject,body);
}
I have changed the website address and goo.gl short code for obvious reasons!
It looks like your comparison value is misspelled:
Should it be Maintenance instead of Mantenance:
if (SourceValue == "08 - Mantenance Request System") {
var recipient = "engineering.support#websiteaddress";
//Start with first depot in list
} else if (LocationValue == depot01) {
var recipient = email01;
And I'd use triple equal signs for comparison:
if (SourceValue === "08 - Maintenance Request System") {
You can search a post like this one for the difference:
Stack Overflow Link