I have build an Sheets Add-on Which performs a task based on trigger setup by user
So the problem is that User sets triggers for multiple sheets e.g Sync
the trigger is executed but only for 1st trigger in the list of triggers not all
The PROBLEM IS only one trigger is being triggered for all of the setup triggers
Logs for one trigger & the same logs comes for all triggers
Active Trigger: -5962537404932988746 for function: fetchSynctriggerWithDetails
Active Trigger: -9139074510508922527 for function: fetchSynctriggerWithDetails
Active Trigger: -1495623190131824397 for function: fetchSynctriggerWithDetails
Active Trigger: -1224866675796805716 for function: fetchSynctriggerWithDetails
Active Trigger: 1983234386806141271 for function: fetchSynctriggerWithDetails
Active Trigger: -8082155554848723508 for function: fetchSynctriggerWithDetails
Response: {"success":true,"triggerDetails":{"trigger_id":"-5962537404932988746","sheet_name":"SKU","databaseid":"1","trigger_time":"1hour"}}
so the problem is it has all the triggers but it always run for
Response: {“success”:true,”triggerDetails”:{“trigger_id”:”-5962537404932988746″,”sheet_name”:”SKU”,”databaseid”:”1″,”trigger_time”:”1hour”}}
Because it can;t find
var triggerId = currentTrigger.getUniqueId();
for each trigger
& each time it returns -5962537404932988746 as current trigger ID
which is wrong
ANY HELP IS APPRECIATED
function createSyncTrigger() {
/// all the setup for setting up trigger
// I am also saving trigger in PropertiesService
PropertiesService.getScriptProperties().setProperty(triggerId, JSON.stringify(triggerDetails));
}
Code snippet to fetch trigger details
function getTriggerDetailsSync() {
var triggers = ScriptApp.getProjectTriggers();
// Log all active triggers for debugging
triggers.forEach(trigger => {
Logger.log('Active Trigger: ' + trigger.getUniqueId() + ' for function: ' + trigger.getHandlerFunction());
});
//var currentTrigger = triggers.find(trigger => trigger.getHandlerFunction() === 'fetchSynctriggerWithDetails');
// Get the current trigger that invoked this function
var currentTrigger = ScriptApp.getProjectTriggers().find(trigger =>
trigger.getHandlerFunction() === 'fetchSynctriggerWithDetails'
);
if (!currentTrigger) {
Logger.log('No trigger found for fetchSynctriggerWithDetails');
return null;
}
var triggerId = currentTrigger.getUniqueId();
}