# onEdit() script won't run when sheet is edited by Glide app

**URL:** <https://community.glideapps.com/t/onedit-script-wont-run-when-sheet-is-edited-by-glide-app/8850>\
**Category:** Ask for Help\
**Created:** [May 10, 2020, 11:22am UTC](https://community.glideapps.com/t/onedit-script-wont-run-when-sheet-is-edited-by-glide-app/8850 "2020-05-10T11:22:45Z")\
**Posts on this page:** 1\
**Showing post:** 15

<div class="post-metadata">

**Author:** ![Robert\_Petitto](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/robert_petitto/32/25193_2.png) [@Robert\_Petitto](https://community.glideapps.com/u/Robert_Petitto)\
**Post date:** [June 17, 2020, 11:37pm UTC](https://community.glideapps.com/t/onedit-script-wont-run-when-sheet-is-edited-by-glide-app/8850/15 "2020-06-17T23:37:09Z")

</div>

I used this method to send SMS messages as emails:

> [@Free push notifications Workaround](https://community.glideapps.com/t/free-push-notifications-solved/6183):
>
> I have a solution for PUSH NOTIFICATIONS. It works with IOS and ANDROID. It is quick and has ZERO cost to everyone. You can do this in your google sheet or a separate sheet that is linked to your original (I used 4 linked sheets, I’ll explain later). 1st you setup on your sheet a variable or value you are wanting to trigger the notification. This data will need a VLOOKUP formula to link to the person you want notified’s phone number and phone carrier, so when the vlaue on the sheet is found usin…

The context is that Chefs will mark the status of the order. This updates column B of my “Orders” sheet.

 ![Screen Shot 2020-06-17 at 7.31.34 PM](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/2X/4/4744bafd2eabd5cc45fd156f991081831e721e11.png)

Columns G-I of this sheet contain the phonenumer@carrier information and a message. The message column (I) is a template that contains the order status and the name of the restaurant.

 ![Screen Shot 2020-06-17 at 7.34.17 PM](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/2X/f/f956d5ba78113ac8e63f756acee2bb589681a253.png)

I wanted to send an email (SMS message) when the status changes in Column B to either “Being Prepared” or to “Ready” (there are 4 possible statuses).

Here was the code I used:

```auto
// The column you want to check if something is entered.
var COLUMNTOCHECK = 2;
// Sheet you are working on
var SHEETNAME = 'Orders';

function sendEmails() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getActiveSheet();
  //checks that we're on the correct sheet.
  if(sheet.getSheetName() == SHEETNAME) { 
    var selectedCell = ss.getActiveCell();
    var selectedRow = selectedCell.getRow();
    var dataRange = sheet.getRange(selectedRow, 7, 1, 3);
    var data = dataRange.getValues();
    //checks the column to ensure it is on the one we want to cause the date to appear.
    if(selectedCell.getColumn() == COLUMNTOCHECK) { 
       for (var i = 0; i < data.length; ++i) {
         var row = data[i];
         var emailAddress = row[0]; // First column
         if (emailAddress.match('@') === null){
           continue; // skip this iteration of the loop and go to the next one
         };  
         var message = row[2]; // Third column
         if (message.match('!') === null){
           continue; // skip this iteration of the loop and go to the next one
         };
         if (message.match('complete') !== null){
         continue; // skip this iteration of the loop and go to the next one
         }; 
         var subject = 'Potluck Order Status';
         MailApp.sendEmail(emailAddress, subject, message, {name:'Potluck', noReply: true});
         SpreadsheetApp.flush();
         
       }
      }
  }
}

```

Finally, had to create an onChange trigger since the spreadsheet doesn’t recognize Glide writes-to-sheets as onEdit triggers.

Works like a charm!

---

_[View the full topic](https://community.glideapps.com/t/onedit-script-wont-run-when-sheet-is-edited-by-glide-app/8850)._
