运行子例程
运行子例程。 它可能会返回其参数的新值。
命令可用性: 本地 IBM RPA SaaS 和 IBM RPA
依赖关系
必须使用 Start Subroutine (beginSub) 命令定义子例程。
脚本语法
IBM RPA 的专有脚本语言的语法与其他编程语言类似。 该脚本语法在脚本文件中定义命令的语法。 您可以在 IBM RPA Studio的 脚本 方式下使用此语法。
goSub --label(String) [--assignments(String)]
输入参数
下表显示了此命令中提供的输入参数的列表。 在表中,您可以看到在 IBM RPA Studio的脚本方式及其 Designer 方式等效标签中工作时的参数名称。
| 设计器方式标签 | 脚本方式名称 | 必需的 | 接受的变量类型 | 描述 |
|---|---|---|---|---|
| 名称 | label |
Required |
Text |
要运行的子例程的名称。 输入使用 Start Subroutine ( beginSub) 命令创建的名称。 |
| 赋值 | assignments |
Optional |
Text |
向当前执行中子例程内的参数赋值。 |
示例
示例 1: 以下示例显示命令运行包含消息 "子例程已开始运行" 的子例程。
// 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
示例 2: 在此示例中,该命令运行将项添加到列表的子例程,并打印其值。 当调用子例程时,将指定在列表中插入的项的值。 在执行主例程的过程中,可以多次调用此子例程。
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