I use a script that defines whether the Trigger should be every 1 minute or every 30 minutes depending on a certain value in the spreadsheet.
As there is no way to edit the Trigger, so I need to delete the old one and create a new one.
To delete Trigger I'm using:
function deleteTriggerWithName(name) {
const trs = ScriptApp.getProjectTriggers().map(t => t.getHandlerFunction());
const ts = ScriptApp.getProjectTriggers();
ScriptApp.deleteTrigger(ts[trs.indexOf(name)]);
}
And the complete model to delete and then create a new trigger looks like this:
if (ss.getSheetByName('Clima').getRange("E6").getValue()=="1 MINUTE") {
deleteTriggerWithName("ClimaParaTestes");
Utilities.sleep(1000);
ScriptApp.newTrigger("ClimaParaTestes").timeBased().everyMinutes(1).create();
Utilities.sleep(1000);
} else if (ss.getSheetByName('Clima').getRange("E6").getValue()=="30 MINUTES") {
deleteTriggerWithName("ClimaParaTestes");
Utilities.sleep(1000);
ScriptApp.newTrigger("ClimaParaTestes").timeBased().everyMinutes(30).create();
Utilities.sleep(1000);
} else {
ss.getRange('Clima!E4').copyTo(ss.getRange('Clima!E5'), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
}
However, when the new Trigger is being created, on the page https://script.google.com/home/triggers, in the last run column
appears a message written:
! disable
Message when I click for more information about disabled:
Note: when I create Trigger manually it works perfectly.
Note 2: I tried to change from V8 mode to use the old version of the legacy editor, but I get a syntax error alert in this line of code:
const trs = ScriptApp.getProjectTriggers().map(t => t.getHandlerFunction());
Is there something in my script that might be doing this fail? If I have to change something to use legacy mode, please identify what I need to do and if the issue is not associated with V8 mode, what might be happening?