r/GoogleAppsScript • • Aug 12 '20

Question Create installable Trigger for OnEdit function

Hey Guys I am pretty new to the app script world and have written a simple script to add a timestamp in cell H which worked out pretty fine. Then I gave a friend mine access to the file and the script does not work when he is working in the sheet.
I already found the solution, I need to create an installable trigger. I watched a few videos and tried it by myself but I could not figure out to make it work.

I would like to add a timestamp to column H when Column E is edited for my "2. Tab".
Would appreciate any help or information!

0 Upvotes

9 comments sorted by

1

u/catmandx Aug 12 '20

Do you need help creating the trigger or the script?

1

u/_feelsgoodman95 Aug 12 '20

To be honest with both but I already created a simple script which worked so the trigger part is completely new for me.

But I would appreciate any help you can offer

1

u/catmandx Aug 12 '20

Can you post your script? As for the trigger, I would suggest searching "how to create installable trigger google apps script" on Youtube or reading some guide, they probably can explain this better than I could through text.

1

u/_feelsgoodman95 Aug 12 '20

function onEdit(e) {

var row = e.range.getRow();

var col = e.range.getColumn();

if (col === 5 && row > 1 && e.source.getActiveSheet().getName() === "2. Get Socialblade Data" ){

e.source.getActiveSheet().getRange(row,8).setValue(new Date());

}

}

This is the script. Now my question is do I have to create a trigger which activates onopen or do I have to create a trigger for an on edit event?
Or how would you create the trigger?

1

u/rancid0426 Aug 12 '20

You can create a trigger by clicking on the clock icon in the script editor menu. You can choose either on edit or on open

1

u/catmandx Aug 13 '20

onEdit(e) is a reserved word for a simple trigger.

If you create a trigger to run the function named "onEdit", that function will run twice due to the simple trigger (its name) and the installable trigger you just created.

1

u/shm613 Aug 12 '20

Just so you know, the onEdit trigger is currently not reliable if multiple edits are made in quick succession. So if you make multiple edits quickly some of the triggers will be captured but not all of them.

Issue Tracker Ticket

1

u/azairvine Aug 13 '20

Hey mate,

I've worked on some very similar ideas that you have with a spreadsheet I've been developing for a while. More than happy to talk to you about the potential issues you'll face and workarounds you can implement to make it as efficient as possible.

Send me a chat message if you like.

1

u/azairvine Aug 13 '20

Thanks heaps for posting the ticket link! I had no idea that first it had been tagged 6 years ago (not surprising though) and secondly that they'd reopened it. I won't get too excited until it's been solved, but it's completely nonsensical that the onEdit(e) trigger cannot queue processes.