I see lots of JavaScript references and code snippets on the forum/documentation (like this one) where the execution object is used for a range of useful things, such as:
However, nowhere have I seen an example of how to instantiate the execution object, and when I try to use it I get an error like this:
The process could not be started. :
Cannot instantiate process definition Finswitch_Tx:14:42ef803b-67df-11e8-a127-0242ac11001b: Unable to
evaluate script: ReferenceError: "execution" is not defined in <eval> at line number 7
Similarly this post gives the following examples of logging from JavaScript:
println("Normal print output")
var logger = java.util.logging.Logger;
var log = logger.getLogger("MY_JS_LOGGER");
log.info("I'm logging");
var system = java.lang.System
system.out.println("System out println");
but again, when I
Cannot instantiate process definition Finswitch_Tx:17:9bacc456-67e6-11e8-a127-0242ac11001b: Unable to evaluate script: ReferenceError: "println" is not defined in <eval> at line number 8
Please could you give me an example of how to instantiate access to that execution object, and is there a way to log from JavaScript in a Service Task output??
Thanks @StephenOTT, I thought this might be the case, but why do I get the error:
Unable to evaluate script: ReferenceError: "execution" is not defined in <eval> at line number 7
when this piece of code is executed in a Service Task JavaScript output parameter?
var statusCode = connector.getVariable("statusCode");
if (statusCode != 200) {
throw new Error(connector.getVariable("response"));
}
else {
var output = S(connector.getVariable("response"));
execution.setVariable("testVar", true);
output.prop("success").boolValue=="true";
}
If I take the line containing execution out, it works fine. Are these objects only available in some of the places you can use JavaScript? Perhaps they are not available for use in a Service Task output variable of type JavaScript? connector is available, though, and it is mentioned as one of the âspecial variablesâ along with execution in the page you linked.
Is it the output of the http connector or the output of the task?
Execution is not available when using a connector. You have to use âconnectorâ. This is mentioned in the scripting docs and the http connector docs.
Thank you Stephen. I have just worked that out through experimentation. Thanks for your input, I was trying to use it in the output of the http connector.
@StephenOTT, Iâve been digging in the connector, scripting and script task docs and donât see mention of this limitation - could you point me in the right direction? Iâd like to fully understand it.
Note that you can still access to the execution when inside of connector.
var parentScope = connector.getParentVariableScope()
context.setActivityId(parentScope.getCurrentActivityId());
context.setExecutionId(parentScope.getProcessInstanceId());
context.setProcessDefinitionId(parentScope.getProcessDefinitionId());
BUT see the following thread for more details and how its not a formal public interface, thus there are not guarantees: Error creating incident via javascript
Is it possible from a child process to get the SuperExecution from the parent Call Activity with javascript?
If I write sth like: execution.getSuperExecution().setVariable("myVariableInParentProcess", aValue);
will it work in a javascript script?
I want from a child process to update the value of a variable in the parent process (for some reasons, long-story to explain, the mapping doesnât help me).
Yes. When you use javascript you are using the nashorn engine which gives you access to the java API. When you are using âexecutionâ you are accessing the java API/getting a java interface/object