Creating a workflow script main routine
Create the workflow integration script's main routine.
About this task
In the script's main routine, you can link workflow tasks and variables to the script's subroutines and variables. Then, you can create workflow instances and, if needed, process them.
This procedure uses the IBM RPA Studio's Designer tab.
Inserting commands
In the workflow script, it will be requested to you insert commands. Complete the following steps to it:
- Search for the command name in the IBM RPA Studio Toolbox.
- You can also search for the command verb.
- Drag and drop the command from the Toolbox to the script development area.
- You can double-click to add the command at the bottom of the script structure.
Commands verbs are highlighted in front of command links. You can search the command in the IBM RPA Studio toolbox using verbs.
Creating variables
In the workflow script, the variables will be created directly on the command editor and the values will not be assigned in the variable creation. To create variables in this way, complete the following steps:
- Click the
icon.
- Then, click the
icon.
- On the Define variable (
defVar
) command, in the Name parameter, type the variable name as requested. - In the Type parameter, select the variable type as requested.
- Click the Save button.
Procedure
- Insert the Load Workflow command.
- Enable the Is Local File option.
- In the File parameter, click the folder icon and select the workflow "exampleWorkflow.bpmn". See Connecting workflow tasks for details on how to build the BPMN file for this procedure.
- In the Process parameter, insert the diagram process id.
- In the Workflow output, type "workflow".
- Click the Save button.
- Insert the Map Workflow Activities (
mapWorkflowActivities
) command.- In the Workflow parameter, select the
${workflow}
variable. - In the Mappings parameter, click three times in the plus signal (+) icon.
- In the first Parameter mapping field, type "hello_world_file":
- In the Value field, type "hello_world_file".
- In the second Parameter mapping field, type "hello_world_message".
- In the Value field, type "hello_world_message".
- In the third Parameter mapping field, type "start_message".
- In the Value field, type "start_message".
- Click the Save button.
- In the Workflow parameter, select the
- Insert the Bind Process Variables (
bindProcessVariables
) command.- In the Workflow parameter, select the
${workflow}
variable. - In the Mappings parameter, click four times in the plus signal (+) icon.
- In the first Parameter mapping field, type "startMessage".
- In the Mappings field, create a variable of type Text named "startMessage".
- In the second Parameter mapping field, type "helloWorldType".
- In the Value field, create a variable of type Text named "helloWorldType".
- In the third Parameter mapping field, type "helloWorldMessage".
- In the Value field, create a variable of type Text named "helloWorldMessage".
- In the fourth Parameter mapping field, type "helloWorldFileMessage".
- In the Value field, create a variable of type Text named "helloWorldFileMessage".
- Click the Save button.
- In the Workflow parameter, select the
- Insert the For (
for
) command.- In the Variables parameter, create a variable of type Number named "createInstance".
- In the From parameter, type "1".
- In the To parameter, type "2".
- In the Step parameter, type "1".
- Click the Save button.
- In the For command structure, insert the Create Workflow Instance (
createWorkflowInstance
) command.- In the Workflow parameter, select the
${workflow}
variable. - In the Workflow instance output, type "instance".
- Click the Save button.
- In the Workflow parameter, select the
- The command Next (
next
) was automatically added to the end of the For command structure. - Insert the List Workflow Instances (
listWorkflowInstances
) command.- In the Workflow parameter, select the
${workflow}
variable. - In the Status parameter, select the New option.
- In the Workflow Instance output, type "instancesToExecute".
- Click the Save button.
- In the Workflow parameter, select the
- Insert the For Each (
foreach
) command.- In the Collection parameter, select the
${instancesToExecute}
variable. - In the Variable parameter, select the
${instance}
variable. - Click the Save button.
- In the Collection parameter, select the
- Insert the Execute Workflow Instance (
executeWorkflowInstance
) command.- In the Workflow Instance parameter, select the
${instance}
variable. - Click the Save button.
- In the Workflow Instance parameter, select the
- The command End For Each (
next
) was automatically added to the end of the For command structure.