0

When creating triggers through the ScriptApp class in Google Apps Script, the parameter for the function which the trigger calls is simply a string, for example:

ScriptApp.newTrigger('renewAuthorization')
  .timeBased().everyMinutes(30)
  .create();

RenewAuthorization function is defined as the following:

function renewAuthorization(key) {
  var refreshToken = PropertiesService.getScriptProperties()
      .getProperty(key + "_RefreshToken");
}

The project I am working on necessitates triggering this function with the key value defined- and therefore I cannot indicate that a function should be triggered with a certain set of parameters every 30 minutes, for example, by the string parameter passed to the function.

I am aware of the fact that I can create wrapper functions to call the original function with the key defined. I could do this:

function callRenewAuthorizationForClient1(){
  RenewAuthorization("Client1")
}

and then run the function which creates the trigger in this way:

ScriptApp.newTrigger('callRenewAuthorizationForClient1')
  .timeBased().everyMinutes(30)
  .create();

But for all practical reasons, this isn't an option, as a wrapper function would have to be created every single time a new key is created.

Is there a way, then, to create triggers for calling functions with a certain set of parameters through the code without having to create wrapper functions?

or, if this is impossible,

Is there a way to create these wrapper functions, or maybe some function alias which represents them, without having to go into the code manually?

tehhowch
  • 9,645
  • 4
  • 24
  • 42
  • Possible duplicate of [How can I pass a parameter to a time-based Google App Script trigger?](https://stackoverflow.com/questions/32697653/how-can-i-pass-a-parameter-to-a-time-based-google-app-script-trigger) – tehhowch Mar 18 '19 at 17:42

1 Answers1

0

You'll have to use another script property, saved as "key" and get its value first.

J. G.
  • 1,922
  • 1
  • 11
  • 21
  • Did you look at [the solution](https://stackoverflow.com/a/49101767/9337071) in the suggested duplicate? It specifies this, exactly, but with actual details :) – tehhowch Mar 19 '19 at 03:18