0
votes

I have created a script for my enterprise Google Apps account (script.google.com) to require all users to change their passwords. I've gone into the Google Script settings under Resources > Current Project's Triggers and set the script to run as a time driven event using the Month timer set to "2". The script instead runs every 30 days, not every 60 days. Does anyone have any experience with the project triggers within script.google.com? I tried to call Google to find out why their built in triggers are not functioning as intended and they just tell me that they don't support script.google.com. I need this script to execute every 60 days, and it would seem that setting the project trigger to run every 2 months should work. It doesn't.

Any help is appreciated.

Thanks!

2
Are you creating the trigger with script or from the editor manually?Serge insas
If you can't get it to work every 60 days and it only triggers every 30 days, then you can use the PropertiesService (developers.google.com/apps-script/reference/properties/…) to set a counter, for example when the script runs first time after 30 days counter == 0 and it's incremented by your script to 1, when the trigger run again after another 30 days counter is 2 and your script executes and resets counter to zero. Not ideal, but a workaroundomerio
I'm creating a trigger by selecting "Resources > Current Project's Triggers" within the current project in the script.google.com.. not within the actual script itself. Because of this, I feel as though Google should be able to handle their own pre defined triggering options but it seems like they cant. At least not for me...Zac

2 Answers

0
votes

I believe I see what the issue is here. The 'Month' trigger on Google Apps script actually refers to run monthly on [day of the month] not run every X months.

You can see the the 'Monthly' trigger gives you up to 31 days to choose a trigger from, indicating that if you choose '15' it would trigger on the 15th of every month. I suppose this could be misinterpreted as 'Run every 15 months'.

A possible solution here is to have it run every month on the 31st of each month, as it should skip months where the number if days is less then 31. The roman calendar is split in such a way that generally this means it would run every two months, with some exceptions (July and August are back to back and both have 31 days, as do December and January).

0
votes

To get a bi-monthly trigger you can set the trigger to monthly and then wrap your code in a conditional like such.

The trigger will fire every month on the specified day but the code inside the conditional will only run once every 2 months.

const date = new Date;   
if (date.getMonth() % 2 == 0) {
  // code to execute   
};