0
votes

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?

1

1 Answers

0
votes

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