# Timestamp on switch action

**URL:** <https://community.glideapps.com/t/timestamp-on-switch-action/8277>\
**Category:** Ask for Help\
**Created:** [May 1, 2020, 11:33am UTC](https://community.glideapps.com/t/timestamp-on-switch-action/8277 "2020-05-01T11:33:25Z")\
**Posts on this page:** 13\
**Page:** 2

<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:** [June 17, 2020, 10:15am UTC](https://community.glideapps.com/t/timestamp-on-switch-action/8277/21 "2020-06-17T10:15:05Z")

</div>

> [@Raj\_Mehta](#):
>
> if (r.getColumn() \< 2

This is the part to choose which column.

If you want column C only, you change it to == 3, if you want any columns that are from column C backwards \<= 3 or \< 4.

---

<div class="post-metadata">

**Author:** ![Raj\_Mehta](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/raj_mehta/32/95_2.png) [@Raj\_Mehta](https://community.glideapps.com/u/Raj_Mehta)\
**Post date:** [June 17, 2020, 1:48pm UTC](https://community.glideapps.com/t/timestamp-on-switch-action/8277/22 "2020-06-17T13:48:43Z")

</div>

Thank you very much it has worked!

---

<div class="post-metadata">

**Author:** ![Alexandre\_Caruso](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/alexandre_caruso/32/6240_2.png) [@Alexandre\_Caruso](https://community.glideapps.com/u/Alexandre_Caruso)\
**Post date:** [July 25, 2020, 10:59pm UTC](https://community.glideapps.com/t/timestamp-on-switch-action/8277/23 "2020-07-25T22:59:42Z")

</div>

Hi with all due respect, I’m still learning how to use Glide, but this solution works only when you open the GS file, no?

Because when I toggle a switch in my app, nothing happens. Maybe I’m wrong.  
I’m even if the file is closed it works? I mean the script runs?

Tks.

---

<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 25, 2020, 11:12pm UTC](https://community.glideapps.com/t/timestamp-on-switch-action/8277/24 "2020-07-25T23:12:44Z")

</div>

The script runs when you have added a trigger for it. The trigger will run automatically when there is a change in the sheet.

---

<div class="post-metadata">

**Author:** ![Alexandre\_Caruso](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/alexandre_caruso/32/6240_2.png) [@Alexandre\_Caruso](https://community.glideapps.com/u/Alexandre_Caruso)\
**Post date:** [July 26, 2020, 12:04am UTC](https://community.glideapps.com/t/timestamp-on-switch-action/8277/25 "2020-07-26T00:04:16Z")

</div>

So u dont need to have the file opened? I have to study the trigger! many thx

---

<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 26, 2020, 12:21am UTC](https://community.glideapps.com/t/timestamp-on-switch-action/8277/26 "2020-07-26T00:21:32Z")

</div>

Yeah you don’t have to open the sheet, when the trigger is set to run with an “On change” setup then it will be run automatically.

---

<div class="post-metadata">

**Author:** ![Alexandre\_Caruso](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/alexandre_caruso/32/6240_2.png) [@Alexandre\_Caruso](https://community.glideapps.com/u/Alexandre_Caruso)\
**Post date:** [July 26, 2020, 2:57am UTC](https://community.glideapps.com/t/timestamp-on-switch-action/8277/27 "2020-07-26T02:57:39Z")

</div>

Awesome! Thx so much! It worked! Perfect!

---

<div class="post-metadata">

**Author:** ![Alexandre\_Caruso](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/alexandre_caruso/32/6240_2.png) [@Alexandre\_Caruso](https://community.glideapps.com/u/Alexandre_Caruso)\
**Post date:** [July 27, 2020, 3:15am UTC](https://community.glideapps.com/t/timestamp-on-switch-action/8277/28 "2020-07-27T03:15:54Z")

</div>

onEdit worked but now onChange no.

27 de jul. de 2020 00:10:18 Erro Exception: Cell reference out of range  
at onChange(Código:4:14)

function onChange(e){

var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();  
var r = ss.getActiveCell();

if (r.getColumn() == 7 && ss.getName()==“BaseGlideApp\_v2”) {  
var celladdress =“I”+ r.getRowIndex()  
ss.getRange(celladdress).setValue(new Date()).setNumberFormat(“dd/MM/yyyy hh:mm”);  
}

var row = e.range.getRow();  
var col = e.range.getColumn();

if (col == 7 && e.source.getActiveSheet().getName() == “BaseGlideApp\_v2”){  
e.source.getActiveSheet().getRange(row,9).setValue(new Date()).setNumberFormat(‘dd/MM/yyyy hh:mm’);  
e.source.getActiveSheet().getRange(e.source.getActiveSheet().getLastRow(),6).setValue(‘última linha’);

}

---

<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 27, 2020, 3:24am UTC](https://community.glideapps.com/t/timestamp-on-switch-action/8277/29 "2020-07-27T03:24:59Z")

</div>

It’s strange. Can you copy the data to a duplicated sheet and share to [ariesarsenal@gmail.com](mailto:ariesarsenal@gmail.com) so I can have a look?

Also, just to be sure, you want 3 actions for an action, to set current timestamp to column 7 & 9, and the value ‘última linha’ to column 6?

---

<div class="post-metadata">

**Author:** ![wjcv06](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/wjcv06/32/12747_2.png) [@wjcv06](https://community.glideapps.com/u/wjcv06)\
**Post date:** [October 8, 2020, 9:07pm UTC](https://community.glideapps.com/t/timestamp-on-switch-action/8277/30 "2020-10-08T21:07:58Z")

</div>

It doesn’t work when the changes are made with Glide. 😕

---

<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:** [October 8, 2020, 10:28pm UTC](https://community.glideapps.com/t/timestamp-on-switch-action/8277/31 "2020-10-08T22:28:36Z")

</div>

Have you added an “on change” trigger?

---

<div class="post-metadata">

**Author:** ![wjcv06](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/wjcv06/32/12747_2.png) [@wjcv06](https://community.glideapps.com/u/wjcv06)\
**Post date:** [October 9, 2020, 2:13am UTC](https://community.glideapps.com/t/timestamp-on-switch-action/8277/32 "2020-10-09T02:13:01Z")

</div>

my bad, it works with the trigger 👍

---

<div class="post-metadata">

**Author:** ![Sales\_Manager](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/sales_manager/32/16172_2.png) [@Sales\_Manager](https://community.glideapps.com/u/Sales_Manager)\
**Post date:** [April 7, 2022, 11:44am UTC](https://community.glideapps.com/t/timestamp-on-switch-action/8277/33 "2022-04-07T11:44:23Z")

</div>

Dear, did you find a solution for this?  
I am looking for the same thing.

[Previous page](https://community.glideapps.com/t/timestamp-on-switch-action/8277.md?page=1)
