What is the nature of the argument you want to pass? It’s not clear from the code.
There are two ways you can approach this:
-
Use
createTimerWithArgumentas demonstrated in Justin’s link. -
Use a function generator.
If the variable passed is created inside this forEach a function generator may be a better choice. The problem is JavaScript passes variables by reference. What that means is your forEach will run and pass that variable but when the timers go off, all the Timers will see the last value that variable had instead of the value it had when createTimerWithArgument was called.
A “function generator” is just a fancy name for a function that creates another function. You’ll pass the variables to the function and that is enough to “fix” the value.
var testFunctionGenerator = function (argument) {
return function() {
// timer code goes here
};
};
...
scriptExecution.createTimer(zonedDateTime.now().plusSeconds(5), testFunctionGenerator(?para?));