1

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

enter image description here

Message when I click for more information about disabled:

enter image description here

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?

Digital Farmer
  • 1,705
  • 5
  • 17
  • 67
  • 1
    Instead of doing this `ss.getSheetByName('Clima').getRange("E6").getValues()[0][0]` do this `ss.getSheetByName('Clima').getRange("E6").getValue()` this won't fix your current problem. – Cooper Jun 20 '21 at 22:58
  • 1
    https://issuetracker.google.com/issues/150756612?pli=1 Unfortunately from what I've seen about the V8 Runtime, there is a general problem about creating Triggers, it's been happening for a long time and it still hasn't been resolved, I think I'll be unanswered for a while. Thank you very much for the tip quoted in the message above, Cooper! – Digital Farmer Jun 21 '21 at 00:08
  • 1
    The rhino engine doesn’t handle ES6 – Cooper Jun 21 '21 at 03:31
  • 1
    Maybe you should just stick with the one minute trigger and then decide on the script whether you want to run it every Trigger or every 30 triggers – Cooper Jun 21 '21 at 03:34
  • 1
    In order to reproduce this, can you clarify how is the trigger-creating function is being executed? Is it fired by a trigger? If that's the case, what kind of trigger? – Iamblichus Jun 21 '21 at 07:24
  • 2
    Hi @lamblichus Yes, initially I create a trigger manually to fire every 30 minutes, and according to the values that exist in the spreadsheet after updating the data, it defines whether it can continue every 30 minutes or if it needs to change to fire every 1 minute . – Digital Farmer Jun 21 '21 at 13:53
  • I'm voting to close this question as duplicate of [Why does time-based GAS Trigger get disabled for unknown reason in V8?](https://stackoverflow.com/questions/60455263/why-does-time-based-gas-trigger-get-disabled-for-unknown-reason-in-v8). – Iamblichus Jun 22 '21 at 09:44

0 Answers0