# Row Modified timestamp

**URL:** <https://community.glideapps.com/t/row-modified-timestamp/13185>\
**Category:** Ask for Help\
**Created:** [July 28, 2020, 4:00am UTC](https://community.glideapps.com/t/row-modified-timestamp/13185 "2020-07-28T04:00:09Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jeremy\_P](https://avatars.discourse-cdn.com/v4/letter/j/13edae/32.png) [@Jeremy\_P](https://community.glideapps.com/u/Jeremy_P)\
**Post date:** [July 28, 2020, 4:00am UTC](https://community.glideapps.com/t/row-modified-timestamp/13185/1 "2020-07-28T04:00:09Z")

</div>

Is there a clever way to make a row modified timestamp? This is so I can sort a list by date modified. The onEdit trigger doesn’t work since Glide updates the sheet with a script/api. Thanks in advance!

---

<div class="post-metadata">

**Author:** ![mthakershi](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/mthakershi/32/1715_2.png) [@mthakershi](https://community.glideapps.com/u/mthakershi)\
**Post date:** [July 28, 2020, 4:34am UTC](https://community.glideapps.com/t/row-modified-timestamp/13185/2 "2020-07-28T04:34:34Z")

</div>

> [@Get Last Modified Date When Cell is changed](https://community.glideapps.com/t/get-last-modified-date-when-cell-is-changed/12359/4):
>
> This is how I do it. I have a function in my script associated with “On change” event. I handle EDIT, INSERT\_ROW with it. function changeTriggerProcessing(e) { // Logger.log(e.changeType); let sheetName = e.source.getActiveSheet().getName(); // in case of EDIT, the way to get active sheet is different if (e.changeType == "EDIT") { sheetName = SpreadsheetApp.getActiveSheet().getName(); } if ( e.changeType == "EDIT" && sheetName == "SHEET\_1" && SpreadsheetApp.getAc…

Something like this.

---

<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 28, 2020, 4:57am UTC](https://community.glideapps.com/t/row-modified-timestamp/13185/3 "2020-07-28T04:57:02Z")

</div>

If you are using the built in edit function, you can use the date time special value.

---

<div class="post-metadata">

**Author:** ![IgorMartynov](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/igormartynov/32/4740_2.png) [@IgorMartynov](https://community.glideapps.com/u/IgorMartynov)\
**Post date:** [July 28, 2020, 7:04am UTC](https://community.glideapps.com/t/row-modified-timestamp/13185/4 "2020-07-28T07:04:55Z")

</div>

Use onchange instead. But, sometimes, it fired not on the single cell but on the range of cells.

---

<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 28, 2020, 7:20am UTC](https://community.glideapps.com/t/row-modified-timestamp/13185/5 "2020-07-28T07:20:39Z")

</div>

This is the best way to handle it if he’s using the edit pencil in my opinion. Point the current datetime special value to a “Last edit” column and you’re set.

---

<div class="post-metadata">

**Author:** ![clevergrant](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/clevergrant/32/11431_2.png) [@clevergrant](https://community.glideapps.com/u/clevergrant)\
**Post date:** [August 1, 2020, 7:16pm UTC](https://community.glideapps.com/t/row-modified-timestamp/13185/6 "2020-08-01T19:16:43Z")

</div>

This is what I ended up using, which has the added benefit of working on all of the sheets, because it only looks for a column with “Modified Date” in the first row (also, it won’t modify the first row):

```
function onChange(e) {

	const sheet = SpreadsheetApp.getActiveSheet()

	const rowIndex = (function() {
		switch (e.changeType) {
			case "EDIT":
				return sheet.getActiveCell().getA1Notation().replace(/\D/g, "").trim()
			case "INSERT_ROW":
				return sheet.getLastRow()
			default:
				throw new Error(`This function can't handle changeType: ${e.changeType}`)
		}
	})()

	const column = sheet.getDataRange().getValues()[0].indexOf("Modified Date") + 1

	if (rowIndex != 1 && column !== 0)
		sheet.getRange(rowIndex, column).setValue(new Date())
}

```

NOTE: This works based on a trigger, so after adding this function to the project, you have to create an “On change” trigger to run it.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/2X/7/77047c77bd6266d10300be923cd3c27e4fff6b67.png)

---

<div class="post-metadata">

**Author:** ![simpler](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/simpler/32/1379_2.png) [@simpler](https://community.glideapps.com/u/simpler)\
**Post date:** [November 26, 2020, 8:06am UTC](https://community.glideapps.com/t/row-modified-timestamp/13185/7 "2020-11-26T08:06:02Z")

</div>

Hi there, I tried this but I get an error message “cannot read change type” for this line in your code, “switch (e.changeType)”. What am I missing?

---

<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:** [November 26, 2020, 9:10am UTC](https://community.glideapps.com/t/row-modified-timestamp/13185/8 "2020-11-26T09:10:19Z")

</div>

> [@simpler](#):
>
> cannot read change type

Did you run the script manually using the “run” button?

---

<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:** [November 26, 2020, 9:13am UTC](https://community.glideapps.com/t/row-modified-timestamp/13185/9 "2020-11-26T09:13:18Z")

</div>

Anyway, this can be handled natively by Glide though, can you specify why you want a script?

> [@Row Modified timestamp](https://community.glideapps.com/t/row-modified-timestamp/13185/3):
>
> If you are using the built in edit function, you can use the date time special value.

---

<div class="post-metadata">

**Author:** ![simpler](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/simpler/32/1379_2.png) [@simpler](https://community.glideapps.com/u/simpler)\
**Post date:** [November 26, 2020, 9:30am UTC](https://community.glideapps.com/t/row-modified-timestamp/13185/10 "2020-11-26T09:30:14Z")

</div>

I got it to work with this code in the end… Do you mean the built in edit pen function? It’s not intuitive to users and I have only so much phone screen space to place instructional text. End users are not tech savvy.

function onChange(e) {

var s = SpreadsheetApp.getActiveSheet();

if( s.getName() == “sheet1” ) { //checks that we’re on the correct sheet

var r = s.getActiveCell();

if( r.getColumn() == 1 ) { //checks the column

var nextCell = r.offset(0, 1);

if( nextCell.getValue() === ‘’ ) //is empty?

nextCell.setValue(new Date());

}

}

}

---

<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:** [November 26, 2020, 9:39am UTC](https://community.glideapps.com/t/row-modified-timestamp/13185/11 "2020-11-26T09:39:39Z")

</div>

Or you can use the set column action on buttons to provide a better experience for non tech-savvy users.

---

<div class="post-metadata">

**Author:** ![simpler](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/simpler/32/1379_2.png) [@simpler](https://community.glideapps.com/u/simpler)\
**Post date:** [November 28, 2020, 2:32pm UTC](https://community.glideapps.com/t/row-modified-timestamp/13185/12 "2020-11-28T14:32:10Z")

</div>

Thanks for that! That’s much better than google script:-)  
Thank you ThinhDinh for looking into this, much appreciated!

---

<div class="post-metadata">

**Author:** ![simpler](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/simpler/32/1379_2.png) [@simpler](https://community.glideapps.com/u/simpler)\
**Post date:** [November 28, 2020, 3:56pm UTC](https://community.glideapps.com/t/row-modified-timestamp/13185/13 "2020-11-28T15:56:00Z")

</div>

Sorry to bother you again Thinh but when it’s submitted, the form notification says “error!” instead of “success”. How to change or disable?

---

<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:** [November 28, 2020, 10:35pm UTC](https://community.glideapps.com/t/row-modified-timestamp/13185/14 "2020-11-28T22:35:00Z")

</div>

Can you clarify why it says “error”?

---

<div class="post-metadata">

**Author:** ![simpler](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/simpler/32/1379_2.png) [@simpler](https://community.glideapps.com/u/simpler)\
**Post date:** [December 8, 2020, 1:39pm UTC](https://community.glideapps.com/t/row-modified-timestamp/13185/15 "2020-12-08T13:39:21Z")

</div>

Sorry about this. For some reason, the error has ‘gone away’!
