trigger spreadsheet is edited error

45 views
Skip to first unread message

nagastar

unread,
Mar 18, 2023, 2:37:41 AM3/18/23
to Google Apps Script Community
why if you create a trigger if the spreadsheet is edited it will always send an email when any column is edited?
 I just want when the edited checkbox is checked then the email comes. 
but when I delete the trigger and I check the checkbox the email doesn't come at all.
any body help?

this is my script

function onEdit(e) {
  

var range = e.range;
var col = range.getColumn();
var row = range.getRow();
var edited_value = e.value;
var ss = e.range.getSheet();


if(col == 10 && edited_value == "TRUE" && ss.getRange("A"+row).getValue() == "")
{

Browser.msgBox("Check If You Have Data In Column A ")

}else
{

var to = "xxx...@gmail.com";
var subject = ss.getRange("B"+row).getValue();
var Email_body = ss.getRange("C"+row).getValue();


MailApp.sendEmail(to,subject,Email_body)


}


} 

cbmserv...@gmail.com

unread,
Mar 18, 2023, 3:03:20 PM3/18/23
to google-apps-sc...@googlegroups.com

You need to add in code to just return if the wrong column or cell was modified.

 

Here is an updated script for you to try: (note I changed function name, the onEdit function name is reserved for simple triggers only, do not use it for installable triggers).

 

Also added an additional ui.alert to print out the value for debugging purposes, comment it out when you are happy with your testing.

 

function triggerOnEdit(e) {

  var ui = SpreadsheetApp.getUi();

  var sheetname = e.source.getSheetName();

  var row = e.range.getRow();

  var col = e.range.getColumn();

  var edited_value = e.value;

  ui.alert("Spreadsheet Editted. Sheet: " + sheetname + " Row: " + row + " Column: " + col + " Value: " + edited_value);  

 

  var ss = e.range.getSheet();

 

if(!(col == 10 && edited_value == "TRUE" ))

{return;}

 

if (ss.getRange("A"+row).getValue() == "")

{

  ui.alert("Check If You Have Data In Column A ")

  return;

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/6da77094-0c26-4a71-923f-c7a0d5676738n%40googlegroups.com.

nagastar

unread,
Mar 19, 2023, 9:50:42 PM3/19/23
to Google Apps Script Community
thank you, I tried it and it went well. you saved me again thank you :)

nagastar

unread,
Mar 19, 2023, 10:55:57 PM3/19/23
to Google Apps Script Community
can u check in sir?
On Sunday, March 19, 2023 at 4:03:20 AM UTC+9 George wrote:
Reply all
Reply to author
Forward
0 new messages