1
votes

I have a function that I run in Apps Scripts via a trigger every 15 minutes. This is apparently too much as it runs on the weekends when is unnecessary. Id like to be able to run this script every fifteen minutes Monday - Friday only. I know you can do this through a cron job but I am trying to determine if I can accomplish this via Apps Scripts Triggers.

The Documentation is not cleared on this or maybe I am missing something.

Does anyone know if this is something that can be done via Google Apps Scripts?

2
Yes by just checking for the appropriate days within your script. Date().getDay() Sun-Sat 0 - 6 don't run the function on 0 or 6 or run the function from 1-5 your choiceCooper
@Cooper Im no t sure I am following. is this something that is custom written inside of your script as suppose to an actual Trigger?chewie
It's javascript. You really need to javascript if you want learn google apps scriptCooper
@Cooper I understand that, however, I am not sure where to place it. Does that go inside the same function?chewie
Please show what you tried and add a brief description of your search efforts as is suggested in How to Ask.Rubén

2 Answers

0
votes
function myfunc() {
  let dt=new Date().getDay();
  if(dt>0 && dt<6) {
  //do stuff here
  }
}

Date().getDay()

0
votes

You can create a trigger (really triggers) like that programmatically.

Example:

function createTriggers() {

var triggers = ScriptApp.getProjectTriggers();
if(triggers.length == 0){
  ScriptApp.newTrigger('myFunction')
      .timeBased()
      .onWeekDay(ScriptApp.WeekDay.MONDAY)
      .everyMinutes(15)
      .create();
      
      ScriptApp.newTrigger('myFunction')
      .timeBased()
      .onWeekDay(ScriptApp.WeekDay.TUESDAY)
      .everyMinutes(15)
      .create();
      
      ScriptApp.newTrigger('myFunction')
      .timeBased()
      .onWeekDay(ScriptApp.WeekDay.WEDNESDAY)
      .everyMinutes(15)
      .create();
      
      ScriptApp.newTrigger('myFunction')
      .timeBased()
      .onWeekDay(ScriptApp.WeekDay.THURSDAY)
      .everyMinutes(15)
      .create();
      
      ScriptApp.newTrigger('myFunction')
      .timeBased()
      .onWeekDay(ScriptApp.WeekDay.FRIDAY)
      .everyMinutes(15)
      .create();
      }}

Documentation here.