简体   繁体   中英

If function using google sheet script

I am a novice in google sheet script and I am trying to send a notification email to myself if a certain cell in a sheet is equal to 1. I have tried countless different approaches without success and would be grateful for help on this function. The function does not seem to be consistent in when to send the email, it seems as the If-function does not work. In my case, the D4 is a 1/0-variable.

My code looks as follows:

function myFunction(SHBA) {

      var ss = SpreadsheetApp.getActiveSpreadsheet ();
      var sheet = ss.getSheetByName('Sheet1'); 
      var range = sheet.getRange("D4")
      var dummy1 = range.getValue();
      if(dummy1 = 1){
          MailApp.sendEmail("rickard.bergqvist@tlk.nu", "SHB byt till A", "Spreadmodell"); 
        }
      }

Try this:

function myFunction(SHBA) {
  var ss=SpreadsheetApp.getActive();
  var sheet=ss.getSheetByName('Sheet1'); 
  var range=sheet.getRange("D4")
  var dummy1=range.getValue();
  if(dummy1 == 1){
    MailApp.sendEmail("rickard.bergqvist@tlk.nu", "SHB byt till A", "Spreadmodell"); 
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM