Run Subroutine
Runs a subroutine. It might return new values for its parameters.
Command availability: IBM RPA SaaS and IBM RPA on premises
Dependencies
You must define a subroutine with the Start Subroutine (beginSub
) command.
Script syntax
IBM RPA's proprietary script language has a syntax similar to other programming languages. The script syntax defines the command's syntax in the script file. You can work with this syntax in IBM RPA Studio's Script mode.
goSub --label(String) [--assignments(String)]
Input parameters
The following table displays the list of input parameters available in this command. In the table, you can see the parameter name when working in IBM RPA Studio's Script mode and its Designer mode equivalent label.
Designer mode label | Script mode name | Required | Accepted variable types | Description |
---|---|---|---|---|
Name | label |
Required |
Text |
Name of the subroutine to run. Enter the name created with the Start Subroutine ( beginSub ) command. |
Assignments | assignments |
Optional |
Text |
Assigns values to parameters within the subroutine in the current execution. |
Example
Example 1: The following example shows the command runs a subroutine that contains the message "The subroutine started running".
// Runs the subroutine
goSub --label NewRoutine
// Starts the subroutine
beginSub --name NewRoutine
// Prints the message informing that the subroutine started running.
logMessage --message "The subroutine started running!" --type "Info"
// Ends the subroutine
endSub
Example 2: In this example, the command runs a subroutine that adds an item to a list, and prints its value. The value of the item that is inserted in the list is assigned when the subroutine is called. This subroutine can be called multiple times throughout the execution of the main routine.
defVar --name exampleCollection --type List --innertype String --value "[item1,item2,item3,item4]"
defVar --name index --type Numeric --value 5
defVar --name exampleItem --type String
defVar --name success --type Boolean
// Runs the subroutine
goSub --label addItem --assignments "{\"${exampleItem}\":\"exampleValue\"}"
// Starts the subroutine
beginSub --name addItem
// Inserts an item to a list
insert --index "${index}" --value "${exampleItem}" --collection "${exampleCollection}"
// Prints the message informing that the item was successfully added into the list.
logMessage --message "Item added to the list: ${exampleItem}" --type "Info"
// Ends the subroutine
endSub