Preparing a workflow with multiple outcomes
Within ESB, workflows can get big and complex. It is possible that a certain workflow item will respond differently than expected. You can set several fail-safes, so that if a certain workflow fails to execute, the workflow could still carry on. Read on if you want to know how to do this. The supported conditions used in the links are as followed:
- + for all the positive numbers
- - for all the negative numbers
- +,- for any value except 0
- 0 for 0
- -1 for -1
- 0,2:4 for 0, 2, 3, and 4
- * for any value
NOTE: This method only works with commandline exit codes. The example below will show a batch script that will do such a thing. However, it also works with Job Executions with the ICM_Action-element, since it also returns a exit code. This example will assume that you know already know the basics of ESB, such as linking elements together and configuring them.
Create a workflow
First off, start by creating a workflow with several elements. Link them together as you normally would, like the figure below (Figure 1).
Figure 1: A basic workflow in ESB
Now, add two workflow-elements at the end and link those as shown below (Figure 2). The green arrows that you see are not only markers to show you what direction the workflow will go to but they can also check if a certain workflow-element is completed correctly. That way it enables you to change the course of the flow.
Figure 2: Change the course of the workflow
As described above, we'll use a Batch script to return a result. To do this, there needs to be a small script to set the result code. An example could be: Batch or Command file:
::Your typical batch code here... and end with EXIT /B %1 EXIT %1
Save this in a .bat file and remember the location. The %1 is a variable for the first parameter in the execution string as an example, but this would be your own variable of course. Then in ESB, at the "Program to run"-property fill in cmd.exe and at the "Program arguments"-property type: /c [PATH_TO_FILE]\[FILENAME].bat -1 (See Figure 3)
Figure 3: ExecuteCommandLine
When the workflow gets triggered, it will run the batch script above. That script will return whatever the first parameter after the filename is. In this case, that's -1. So the workflow will go via the OIP_Action2-element. However, if that last parameter is 0, it will directly go to the ICM_Action1-element and will skip the OIP_Action2-element. This way of creating workflows can be incredibly useful, especially if you combine it with the ExecuteJob functionality (this can be found in the Service-property of a ICM_Action-element). That function also fires a commandline function, which will return resultCodes.