0

I have three Google Script functions in a Google Document (we'll call them functionOne, functionTwo and functionThree). What I would like to do is create a new function (we'll call it newFunction) that will run every Friday at 7 am using triggers (this part I know how to do).

What I am having a hard time with is I would like newFunction to call one of functionOne, functionTwo or functionThree in a specific order.

For example, the first Friday, I want functionOne ran, the next Friday functionTwo, the third Friday functionThree and then loop.

How would I be able to accomplish this?

Thanks in advance.

0

May be you need something like this

function newFunction() {
  var order =
    PropertiesService.getScriptProperties().getProperty('order') || '1';
  switch (order) {
    case '1':
      functionOne();
      break;
    case '2':
      functionTwo();
      break;
    case '3':
      functionThree();
      break;
  }
  var nextOrder = '' + (+order < 3 ? +order + 1 : '1');
  PropertiesService.getScriptProperties().setProperty('order', nextOrder);
}

You can use an external properties store for save the current state of the app. As you can see there is no need to specified a week day.

  • Hey contributorpw, thanks for the help. When I put the above code in and try to run the function, it runs without any errors, but it does not do what I would expect it to. functionOne, functionTwo or functionThree does not run. – Ryan Sep 3 at 15:16
  • @Ryan Sorry this is my fault. It's fixed now. See var order = ... – contributorpw Sep 3 at 17:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.