0

I have a spreadsheet that logs incoming answered and missed calls in Google Drive. It is currently set to send an email every hour between 10am and 7pm.

Ideally I would like it to not send the email during the weekend. Setting up each hour Monday to Friday uses too many triggers.

Is there a way to construct a trigger that will send an email every hour (10am to 7pm) only Monday to Friday?

I've read the documentation at Google and a few (unrelated as it turns out) examples on here and I am stumped!

I tried putting a load of trigger conditions together:

function autoSendHourly() {
ScriptApp.newTrigger("hourlyUpdate()")
   .timeBased()
   .onWeekDay(ScriptApp.WeekDay.MONDAY)
   .onWeekDay(ScriptApp.WeekDay.TUESDAY)
   .onWeekDay(ScriptApp.WeekDay.WEDNESDAY)
   .onWeekDay(ScriptApp.WeekDay.THURSDAY)
   .onWeekDay(ScriptApp.WeekDay.FRIDAY)
   .atHour(10)
   .atHour(11)
   .atHour(12)
   .atHour(13)
   .atHour(14)
   .atHour(15)
   .atHour(16)
   .atHour(17)
   .atHour(18)
   .atHour(19)
   .create();
}

I wasn't entirely surprised that it didn't work, but I was mildly surprised that it threw up no errors.

Any help (including "you're mad it can't be done") would be greatly appreciated.

ItIsIan
  • 3
  • 2

2 Answers2

3

The simplest thing to do is use the create trigger like you did but for every hour every day and then in you handler function add a small piece of code that will return if day and time don't meet specific conditions like explained in this (old) post.

the code may look like something like this :

function officeHours(){
  var nowH=new Date().getHours();
  var nowD=new Date().getDay();
  Logger.log('day : '+nowD+'   Hours : '+nowH)
  if(nowH>17||nowH<8||nowD==6||nowD==0){return}
  Browser.msgBox('time to work !');//normally your real function should begin here...
}
Community
  • 1
  • 1
Serge insas
  • 45,904
  • 7
  • 105
  • 131
  • I had just come to that conclusion myself. I made the mistake of just fixating on trying to use triggers rather than doing the sensible thing. Thanks. – ItIsIan Feb 27 '14 at 16:04
-1

I haven't messed around with java in awhile but this article might help.

Android: how to get the current day of the week (Monday, etc...) in the user's language?

If it was me, I would get the day of the week and check it in a switch. Then if it matches a week day call a function to check the time between 10am and 7pm.

Best of luck.

Community
  • 1
  • 1
Martin E.
  • 267
  • 1
  • 12