# Trigger script onEdit event from App

**URL:** <https://community.glideapps.com/t/trigger-script-onedit-event-from-app/6795>\
**Category:** Ask for Help\
**Created:** [April 11, 2020, 1:26pm UTC](https://community.glideapps.com/t/trigger-script-onedit-event-from-app/6795 "2020-04-11T13:26:13Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mrinal\_Chakraborty](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/mrinal_chakraborty/32/5239_2.png) [@Mrinal\_Chakraborty](https://community.glideapps.com/u/Mrinal_Chakraborty)\
**Post date:** [April 11, 2020, 1:26pm UTC](https://community.glideapps.com/t/trigger-script-onedit-event-from-app/6795/1 "2020-04-11T13:26:13Z")

</div>

Hi  
I have written a script which needs to run when ever user enter new data. Pl let me know how to achieve that.

---

<div class="post-metadata">

**Author:** ![Mrinal\_Chakraborty](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/mrinal_chakraborty/32/5239_2.png) [@Mrinal\_Chakraborty](https://community.glideapps.com/u/Mrinal_Chakraborty)\
**Post date:** [April 11, 2020, 2:07pm UTC](https://community.glideapps.com/t/trigger-script-onedit-event-from-app/6795/2 "2020-04-11T14:07:56Z")

</div>

I have solved this issue with onChange(e)

---

<div class="post-metadata">

**Author:** ![Laurent\_Girardeau](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/laurent_girardeau/32/1316_2.png) [@Laurent\_Girardeau](https://community.glideapps.com/u/Laurent_Girardeau)\
**Post date:** [April 24, 2020, 12:31pm UTC](https://community.glideapps.com/t/trigger-script-onedit-event-from-app/6795/3 "2020-04-24T12:31:38Z")

</div>

Hello  
I cannot recover data with onEdit (e). All of my data seems undefined. Could you give me a sample code that works to inspire me  
thanks in advance

```
function onEdit(e)
{  

 var range = e.range;
  
Logger.log("currentRange"+ range)
Logger.log("currentSource"+ e.source)
Logger.log("value"+ e.value)
Logger.log("Oldvalue"+ e.oldvalue)
}
```

---

<div class="post-metadata">

**Author:** ![Carlos\_DeSilva](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/carlos_desilva/32/19965_2.png) [@Carlos\_DeSilva](https://community.glideapps.com/u/Carlos_DeSilva)\
**Post date:** [April 24, 2020, 1:41pm UTC](https://community.glideapps.com/t/trigger-script-onedit-event-from-app/6795/4 "2020-04-24T13:41:06Z")

</div>

As you can see from the post above, the onEdit(e) event trigger does not work with Glide, only the onChange(e) trigger does.

---

<div class="post-metadata">

**Author:** ![Laurent\_Girardeau](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/laurent_girardeau/32/1316_2.png) [@Laurent\_Girardeau](https://community.glideapps.com/u/Laurent_Girardeau)\
**Post date:** [April 24, 2020, 1:44pm UTC](https://community.glideapps.com/t/trigger-script-onedit-event-from-app/6795/5 "2020-04-24T13:44:33Z")

</div>

Thank you  
do you have a little bit of code to find out which cell has been modified?

---

<div class="post-metadata">

**Author:** ![Mrinal\_Chakraborty](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/mrinal_chakraborty/32/5239_2.png) [@Mrinal\_Chakraborty](https://community.glideapps.com/u/Mrinal_Chakraborty)\
**Post date:** [April 24, 2020, 1:50pm UTC](https://community.glideapps.com/t/trigger-script-onedit-event-from-app/6795/6 "2020-04-24T13:50:46Z")

</div>

Simply change the name of function to onChange(e) and assign spreadsheet trigger. Now your code will work with Glide.

---

<div class="post-metadata">

**Author:** ![Laurent\_Girardeau](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/laurent_girardeau/32/1316_2.png) [@Laurent\_Girardeau](https://community.glideapps.com/u/Laurent_Girardeau)\
**Post date:** [April 24, 2020, 2:08pm UTC](https://community.glideapps.com/t/trigger-script-onedit-event-from-app/6795/7 "2020-04-24T14:08:41Z")

</div>

Thank you  
It is exactly what i do but range is undefined as e.source or e.oldvalue  
Can you help me

 ![Capture d’écran 2020-04-24 à 16.05.50](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/2X/e/e2505c9f2ade8035a76f58c40197703ec73fffc9.png)

---

<div class="post-metadata">

**Author:** ![Carlos\_DeSilva](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/carlos_desilva/32/19965_2.png) [@Carlos\_DeSilva](https://community.glideapps.com/u/Carlos_DeSilva)\
**Post date:** [April 24, 2020, 2:38pm UTC](https://community.glideapps.com/t/trigger-script-onedit-event-from-app/6795/8 "2020-04-24T14:38:59Z")

</div>

The (e) will not return specific cell information, only these triggers:

`changeType` The type of change ( `EDIT` , `INSERT_ROW` , `INSERT_COLUMN` , `REMOVE_ROW` , `REMOVE_COLUMN` , `INSERT_GRID` , `REMOVE_GRID` , `FORMAT` , or `OTHER` ).

---

<div class="post-metadata">

**Author:** ![Laurent\_Girardeau](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/laurent_girardeau/32/1316_2.png) [@Laurent\_Girardeau](https://community.glideapps.com/u/Laurent_Girardeau)\
**Post date:** [April 24, 2020, 2:49pm UTC](https://community.glideapps.com/t/trigger-script-onedit-event-from-app/6795/9 "2020-04-24T14:49:08Z")

</div>

Ok but How to know that cell changed ??

---

<div class="post-metadata">

**Author:** ![Carlos\_DeSilva](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/carlos_desilva/32/19965_2.png) [@Carlos\_DeSilva](https://community.glideapps.com/u/Carlos_DeSilva)\
**Post date:** [April 24, 2020, 4:00pm UTC](https://community.glideapps.com/t/trigger-script-onedit-event-from-app/6795/10 "2020-04-24T16:00:58Z")

</div>

Glide does not pass that to your spreadsheet. You’ll need to write a script that captures that something in the whole spreadsheet has changed, whether it’s adding or removing a row or column or any of the triggers I mentioned above. Then in the script, you’ll reference a change that may be different than the last time an edit was made.

I’ll give you an example script in my next post.

---

<div class="post-metadata">

**Author:** ![Carlos\_DeSilva](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/carlos_desilva/32/19965_2.png) [@Carlos\_DeSilva](https://community.glideapps.com/u/Carlos_DeSilva)\
**Post date:** [April 24, 2020, 4:11pm UTC](https://community.glideapps.com/t/trigger-script-onedit-event-from-app/6795/11 "2020-04-24T16:11:58Z")

</div>

function trailerDelete(e) { //This is the onChange(e) trigger  
var app = SpreadsheetApp;  
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();

var targetSheet = app.getActiveSpreadsheet().getSheetByName(“Report”);  
// You can replace “Report” in the above line, to the sheet that you are referencing.

[//Logger.log](https://Logger.log)(targetSheet.getRange(2, 2).getValue() + " Test");  
if (e.changeType==“EDIT”){  
for (var i = 2; i \< 6;i++){  
if (targetSheet.getRange(i,2).getValue() ==""){  
targetSheet.getRange(i, 3).clear();  
targetSheet.getRange(i, 4).clear();  
targetSheet.getRange(i, 5).clear();  
// The 3 examples above are the columns and corresponding row that need to be //deleted  
}  
}  
}  
}

The example above is what I use to clear a set of values when I check to see if a cell is empty. It iterates through my entire sheet.

I must tell you that the script can take time to run depending on the size of your sheet and how much data you are trying to edit. Also, there is the Glide/Google lag if your account is not pro.

---

<div class="post-metadata">

**Author:** ![Mrinal\_Chakraborty](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/mrinal_chakraborty/32/5239_2.png) [@Mrinal\_Chakraborty](https://community.glideapps.com/u/Mrinal_Chakraborty)\
**Post date:** [April 24, 2020, 4:30pm UTC](https://community.glideapps.com/t/trigger-script-onedit-event-from-app/6795/12 "2020-04-24T16:30:31Z")

</div>

You may use getActiveCell() to identify the cell where modifications done. But one thing, for simple editing purposes you do not require all this information. Glide will automatically edit current row.

---

<div class="post-metadata">

**Author:** ![Laurent\_Girardeau](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/laurent_girardeau/32/1316_2.png) [@Laurent\_Girardeau](https://community.glideapps.com/u/Laurent_Girardeau)\
**Post date:** [April 30, 2020, 1:35pm UTC](https://community.glideapps.com/t/trigger-script-onedit-event-from-app/6795/13 "2020-04-30T13:35:52Z")

</div>

I go step by step by testing the code sent.

the ligne 8 is :"**var targetSheet = app.getActiveSpreadsheet().getSheetByName(“Suivi”);**

**"SyntaxError: Invalid or unexpected token (ligne 8, fichier “Focus.gs”)"**

I don’t understand what could be the problème  
1 function traitement(e)  
2 {  
3 Logger.log(‘change’);  
4 var sheet = spreadsheet.getActiveSheet();  
5 var app = SpreadsheetApp;  
6 var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();  
7  
8 var targetSheet = app.getActiveSpreadsheet().getSheetByName(“Suivi”);

```
}

```

`![Capture d’écran 2020-04-30 à 15.29.45|690x239](upload://o7OqlAEicLAJsCXHX2M2ayNJ5I9.png) `

Thank you

---

<div class="post-metadata">

**Author:** ![Drearystate](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/drearystate/32/49605_2.png) [@Drearystate](https://community.glideapps.com/u/Drearystate)\
**Post date:** [November 10, 2020, 4:08pm UTC](https://community.glideapps.com/t/trigger-script-onedit-event-from-app/6795/14 "2020-11-10T16:08:55Z")

</div>

Hello, I copied and pasted your code and setup pages to match and the code wont even save. Error line 5. Unexpected or Invalid token. So the reason for this error if anyone else from the US attempt to copy and paste is because the quotation marks used are different from ours, they have to be replaced with our quotations marks. They even appear slightly different. (US - " ", the ones in the code - “ “), so be mindful if you use this solution. Also this applies to some code elsewhere on the forums where a single apostrophe is allowed in other countries where full quotes are required in the US.

---

<div class="post-metadata">

**Author:** ![hunaism](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/hunaism/32/48244_2.png) [@hunaism](https://community.glideapps.com/u/hunaism)\
**Post date:** [September 23, 2022, 8:42am UTC](https://community.glideapps.com/t/trigger-script-onedit-event-from-app/6795/15 "2022-09-23T08:42:25Z")

</div>

```auto
function TestFuncion_onChange(e) {
    const ss = e.source;
    const range = ss.getActiveRange();

  if(e.changeType === 'EDIT'){
    Logger.log("currentCell: "+ range.getA1Notation());
    Logger.log("value: "+ range.getValue());         
  }
}

```

---

<div class="post-metadata">

**Author:** ![NoCodeAndy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/nocodeandy/32/62530_2.png) [@NoCodeAndy](https://community.glideapps.com/u/NoCodeAndy)\
**Post date:** [January 17, 2024, 4:49pm UTC](https://community.glideapps.com/t/trigger-script-onedit-event-from-app/6795/16 "2024-01-17T16:49:21Z")

</div>


