Trigger ID Changes After Modifying the Execution Time - Unexpected Behavior

56 views
Skip to first unread message

Leandro dos Santos (xWF)

unread,
Apr 30, 2025, 2:59:43 AM4/30/25
to Google Apps Script Community

Hello everyone,

I'm encountering an unexpected behavior with Google Apps Script triggers and I'm wondering if anyone else has experienced this or has any explanation.

I programmatically created a trigger to execute a function at a specific time. Immediately after creation, I used the getUniqueId() method to obtain and save the ID of this trigger.

Subsequently, I accessed the "Project Triggers" section and modified the execution time of this existing trigger. I saved the changes.

To my surprise, when I ran the code again to list the triggers and check the ID of that specific trigger, I noticed that the ID had changed.

I expected the trigger ID to remain the same, as I only modified the execution time and did not delete and recreate the trigger.

I used the following code to get the ID:

JavaScript
var triggers = ScriptApp.getProjectTriggers(); for (var i = 0; i < triggers.length; i++) { Logger.log("Trigger ID: " + triggers[i].getUniqueId()); }

Has anyone else experienced something similar? Is this the expected behavior or could it be a bug?

Any help or insight into this issue would be greatly appreciated.

Thank you!

Neeraj Sharma

unread,
May 3, 2025, 7:40:03 AM5/3/25
to Google Apps Script Community
May be possible that you are working on two different projects at same browser with different id's.

Leandro dos Santos (xWF)

unread,
May 5, 2025, 9:09:39 AM5/5/25
to Google Apps Script Community
I tested it by creating a trigger using code, then I got the trigger ID, then I manually entered the trigger and changed only the trigger firing time and saved the changes to the trigger. I only had one project open. I checked the trigger ID again, and it was changed again.

Google Pony

unread,
May 8, 2025, 5:52:05 AM5/8/25
to Google Apps Script Community
Hello, Leandro.

Thank you for sharing your observation.  It's an excellent question, and one that may certainly generate misunderstanding.

What you're seeing is anticipated behavior with Google Apps Script.  When you manually adjust the timing or other settings of a trigger in the UI (Project Triggers dashboard), Apps Script deletes the previous trigger and generates a new one behind the scenes.

This basically modifies the getUniqueId() value since you are no longer dealing with the original object; it is a completely different trigger. So, even if it appears that you're "editing" the existing trigger, what occurs within is:
  • The original trigger has been deleted.
  • A new trigger is created with the new parameters.
  • The new trigger is assigned a new unique ID.
This behavior also applies if you modify triggers through the Apps Script UI, not through code.

Recommendation:
If you need to maintain control over a trigger's identity (e.g., for dynamic updates), consider managing all your trigger creation and updates purely through code. 
For example:
// Delete all triggers for a function before re-creating it
const updateTrigger = () => {
  const functionName = 'yourFunctionName';
  ScriptApp.getProjectTriggers().filter(trigger => trigger.getHandlerFunction() === functionName).forEach(trigger => ScriptApp.deleteTrigger(trigger));
  const newTrigger = ScriptApp.newTrigger(functionName).timeBased().at(new Date(Date.now() + 1000 * 60 * 10)).create(); // 10 mins later
  Logger.log("New Trigger ID: " + newTrigger.getUniqueId());
};


This ensures that you're in full control of when triggers are replaced and can track new IDs as needed.

Hope this clarifies things!

Sincerely yours,
Sandeep Kumar Vollala
Consultant
LinkedIn Logo WhatsApp Logo
Reply all
Reply to author
Forward
0 new messages