I have created 3 scripts and I am able to send emails when the cell value has changed my problem is that multiple scripts are getting fired even when the condition is not matched. Below are the 4 Scripts
The following script should only fire when the status is changed to COMPLETE for the range mentioned
function SendEmailToAditya() {
var checkCurrentStatus = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("ToothAcheStatusSheet").getRange("N2:N999");
var statusinfo= checkCurrentStatus.getValues();
if(statusinfo=='COMPLETE'){
{
var EmailMessage = 'Hey AD,VA has finished reviewing toothache.care blog, your time to do the graphics.';
var esubject = 'Graphic Request for Toothache.care';
MailApp.sendEmail('
e...@e.com', esubject, EmailMessage);
}
}
}
function SendEmailToKS() {
var checkCurrentStatus = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("ToothAcheStatusSheet").getRange("S2:S999");
var statusinfo= checkCurrentStatus.getValue();
if(statusinfo=='COMPLETED')
{
var EmailMessage = 'Hey Team,Graphics are ready awaitng final approval';
var esubject = 'Graphic Complete - Sending for approval';
MailApp.sendEmail('
em...@a.com', esubject, EmailMessage);
}
}
The following should fire only when the status is changed to OK and only for the range mentioned
function FinalApproval() {
var checkCurrentStatus = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("ToothAcheStatusSheet").getRange("U2:U999");
var statusinfo= checkCurrentStatus.getValue();
if(statusinfo=='OK')
{
var EmailMessage = 'Good to go for the articles. Please publish';
var esubject = 'Approval from M';
}
}
The following should fire only when the status is changed to DONE and only for the range mentioned
function Donel() {
var checkCurrentStatus = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("ToothAcheStatusSheet").getRange("V2:V999");
var statusinfo= checkCurrentStatus.getValue();
if(statusinfo=='DONE')
{
var EmailMessage = 'Post Published';
var esubject = 'Post Done';
MailApp.sendEmail('
r...@r.com', esubject, EmailMessage);
}
}
The emails are getting fired and I am even receiving the emails, the problem is that when the first script range has data in it and I change the cell value for the range mentioned in the second script it fires both the script and send me two emails and same is with the third if i update the cell value in the range mentioned in the third script and if there is data present already in the first range and second range then it will fire 3 emails.
I am looking out that it should fire email only for the cell value updated for the script. Need guidance on what I am doing wrong.
I have created a trigger for all these 3 scripts on change option inside the trigger.