This tutorial will walk you through setting up a workflow1
calling workflow2
upon completion. Also contains business cases (wait for multiple workflows to complete), and exception handling.
Generic case: workflow1
calls workflow2
with PostEvent
The calling workflow1
contains your business logic and ends with a javascript activity
(containing xtk.workflow.PostEvent()
):
The called workflow2
has a signal activity
and then some logic:
The generic JS call is as follow:
xtk.workflow.PostEvent("workflowInternalName", "signalInternalName", "", <variables/>, false);
So in our case:
var myVar1 = "hello world!";
xtk.workflow.PostEvent("workflow2", "signal", "", <variables var1={myVar1}/>, false);
Start workflow2
(to activate its signal
), then workflow1
. We can see in the logs that the value has been passed over, in a synchronous call:
Logs of workflow1
:
Logs of workflow2
:
/**
* @var workflowId Identifier or internal name of the workflow
* @var activity The name of the activity from which the event starts
* @var transition The name of the transition to activate. If this name is empty, the event will be issued on the first valid transition (expiry type events are ignored).
* @var parameters The parameters of the event in the form of an XML element. The name of the element must be variables. If you do not want to pass a variable, you can use an empty element <variables/> or an empty string "".
* @var complete All pending tasks of the specified activity are finished
*
* @return null
*/
function PostEvent (
String workflowId,
String activity,
String transition,
XML parameters,
Boolean complete
)
References:
## Business case: wait for multiple workflows to be done, then call a final workflow
3 workflows start1
, start2
and start3
needs to be done, before the last workflow final
is executed:
They contain this JS code:
// start1
logInfo('start1 done');
var params = <variables var1="hello"/>;
xtk.workflow.PostEvent("finalWorkflow", "signal1", "", params, false);
// start2
logInfo('start2 done');
var myVar = "var myVar";
var params = <variables var2={myVar}/>;
xtk.workflow.PostEvent("finalWorkflow", "signal2", "", params, false);
// start3
logInfo('start3 done');
var myObject = {key:"value"};
var params = <variables var3={myObject.key}/>;
xtk.workflow.PostEvent("finalWorkflow", "signal3", "", params, false);
The final
workflow contains 3 signals signal1
, signal2
and signal3
, all linked to an AND
activity:
With this code
logInfo('Final');
logInfo('vars.var1', vars.var1);
logInfo('vars.var2', vars.var2);
logInfo('vars.var3', vars.var3);
Run the last workflow, then the 3 first, and you’ll have the following logs:
## Business case: exception handling
We can simulate a try
/catch
/finally
:
Will be equivalent to the following pseudo-code:
processA() // will stop the workflow if error
try {
// @throw NoFileException, ConnectionException
ftpDownload() // will not stop the workflow
// @throw GenericException
processB() // will not stop the workflow
} catch(exception) {
alert()
} finally {
CallToFinalWorkflow()
}