# 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:** 8\
**Page:** 2

<div class="post-metadata">

**Author:** ![John\_Cabrera](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/john_cabrera/32/2066_2.png) [@John\_Cabrera](https://community.glideapps.com/u/John_Cabrera)\
**Post date:** [July 16, 2020, 6:14am UTC](https://community.glideapps.com/t/onedit-script-wont-run-when-sheet-is-edited-by-glide-app/8850/21 "2020-07-16T06:14:26Z")

</div>

@Jeff_Hager wow, mystery solved for me too. I’ve been wondering why that onChange is triggering constantly. I do get errors from google pretty regularly, but it doesn’t seem to be affecting anything that I can see, so I just disregard them.

What kind of “if statement” could I write so that it only triggers for certain sheets? What would that look like exactly? I’d like to implement that if I can. My script is only relevant to a few sheets, so there’s no reason for it to trigger on changes to that App: Metadata sheet.

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [July 16, 2020, 7:07am UTC](https://community.glideapps.com/t/onedit-script-wont-run-when-sheet-is-edited-by-glide-app/8850/22 "2020-07-16T07:07:16Z")

</div>

You can use the getSheetByName method, I suppose.

---

<div class="post-metadata">

**Author:** ![John\_Cabrera](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/john_cabrera/32/2066_2.png) [@John\_Cabrera](https://community.glideapps.com/u/John_Cabrera)\
**Post date:** [July 16, 2020, 7:11am UTC](https://community.glideapps.com/t/onedit-script-wont-run-when-sheet-is-edited-by-glide-app/8850/23 "2020-07-16T07:11:28Z")

</div>

I already use that method. It’s part of the fuction itself, so comes after the onChange trigger. How would that affect when the onChange command is triggered? I do have lots of if statements within that function that only perform any actual work if a change has been made to a certain sheet. But I thought Jeff was talking about using an if statement to forgo the onChange command completely under certain conditions.

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [July 16, 2020, 9:44am UTC](https://community.glideapps.com/t/onedit-script-wont-run-when-sheet-is-edited-by-glide-app/8850/24 "2020-07-16T09:44:26Z")

</div>

Oh I use the same method as you, which is to check if the event happens on which sheet and whether to continue or not based on that condition. So the script is actually triggered behind the scenes, but whether it leads to an outcome or not depends on the condition.

---

<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:** [July 16, 2020, 1:12pm UTC](https://community.glideapps.com/t/onedit-script-wont-run-when-sheet-is-edited-by-glide-app/8850/25 "2020-07-16T13:12:33Z")

</div>

The COLUMNTOCHECK specifies column 2 (B). This is the column that contains the values altered by the choice component.

---

<div class="post-metadata">

**Author:** ![Rogelio](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/rogelio/32/1054_2.png) [@Rogelio](https://community.glideapps.com/u/Rogelio)\
**Post date:** [July 16, 2020, 11:52pm UTC](https://community.glideapps.com/t/onedit-script-wont-run-when-sheet-is-edited-by-glide-app/8850/26 "2020-07-16T23:52:30Z")

</div>

I get that bit, but you also said that there are 4 possible order statuses.

Where do you do actual check for the correct status before sending out the notification?

eg; IF COLUMNTOCHECK == “Being Prepared” or “Ready” THEN SEND\_NOTIFICATION

possibly this line, trying to figure this line out?

`if (message.match('complete') !== null)`

---

<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:** [July 17, 2020, 1:38am UTC](https://community.glideapps.com/t/onedit-script-wont-run-when-sheet-is-edited-by-glide-app/8850/27 "2020-07-17T01:38:37Z")

</div>

Right. That’s the one…there are 4 statuses. If null…nothing. If complete…nothing. Which leaves the other two statuses.

---

<div class="post-metadata">

**Author:** ![Jeff\_Hager](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/jeff_hager/32/43_2.png) [@Jeff\_Hager](https://community.glideapps.com/u/Jeff_Hager)\
**Post date:** [July 17, 2020, 3:21am UTC](https://community.glideapps.com/t/onedit-script-wont-run-when-sheet-is-edited-by-glide-app/8850/28 "2020-07-17T03:21:25Z")

</div>

Check out the script here. Here you can see that the script only continues if the active sheet is “Contacts”. It doesn’t mean that the script won’t run at all, but it will just skip over all of the code if the changed active sheet is not the we want to run code against.

> [@Populating multipls tabs from one tab in google-sheet](https://community.glideapps.com/t/populating-multipls-tabs-from-one-tab-in-google-sheet/11716/7):
>
> The concept would be the same. Instead of a single function to copy\_new\_names, you could probably create separate functions to handle each sheet you are adding to. I would also possibly make a duplicate of subscriber and date in between company name and contact email to the getrange in the script works. There are probably better ways to handle this, such as concatenating the 3 columns into one column with a delimiter (such as a pipe “|” or a comma “,”), writing that to the first column like m…

Yes I get occasional errors from Google, but I only have a couple of user’s, so it’s not a big deal. The code that needs to run eventually runs anyway.

[Previous page](https://community.glideapps.com/t/onedit-script-wont-run-when-sheet-is-edited-by-glide-app/8850.md?page=1)
