Runsub

This help page is for CXone Studio. This information is also available for Desktop Studio.

Calls a subscript, which runs and then uses the Return action to return to and continue running the main script. When the subscript runs, it stores a value in the ReturnValue property of the Return action and then passes that value back to the ReturnVariable property in the Runsub action on the main script.

This action can be especially useful if you have one or more larger scripts that you'd rather break into smaller scripts.

Dependencies

  • The main script and the subscript must be in the same folder.

  • The main script type and the subscript type must be the same. For example, if the main script is a phone script, the subscript must also be a phone script.
  • If you put a Runsub action in the main script, your subscript MUST have a Return action.
  • Runsub can pass multiple variables from the main script to the subscript, but the subscript can return only one value (in the ReturnVariable property) to the main script.
  • Any variables defined in the subscript will no longer be available when the subscript terminates unless you declare them as global. You can do this in a SNIPPET action by adding global: before the variable name. For example, ASSIGN global:varName = value. Another option for accessing data in a subscript is to use the GET /contacts/{contactId}/custom-data An icon of a square with an arrow  pointing from the center out to the upper right corner. API.
  • To use the savetodb() function on a variable in a Runsub subscript, it must be a global variable.
  • All scripts called by RunScript , Spawn, Runsub, or similar scripts must be valid and active. During the save process, Studio validates all scripts called by actions. If any of them are invalid or inactive, Studio displays an error and you won't be able to save.

Supported Script Types

A square with a line branching from it that goes to three other squares.

Generic

Email Chat Phone Voicemail Work Item SMS Digital

Comparison of Similar Actions

The following actions have similar functions, but with some key differences: 

  • Runscript: When Runscript triggers another script, it doesn't return to the first script from the second script.
  • Runsub: When Runsub triggers a subscript, the script can return to the first script, as long as the subscript has a Return action. The Return action provides a value back to the Runsub action when the subscript is finished.
  • SPAWN: Starts a second script that runs in parallel to the first script. Spawned scripts cannot pass data back to the first script unless you include a SIGNAL action in the spawned script.

Input Properties

These properties define data that the action uses when executing.

Property

Description

Add Caption

Enter a short phrase that uniquely identifies this action in the script. The caption appears on the script canvas under the action icon.

Script Name

The script you want to spawn. You can click the Choose Script link at the top of the action's properties box to select a script from your business unit.

Return Variable

The value that is returned to the main script is stored in this property. To pass multiple values, use an array as the variable.
Parameters

Click the ellipsis icon in the field and add a variable for each parameter you want to send to the spawned script. Enter one variable per line in the editor window. Use meaningful variable names. Variable names do not have to match the name of the corresponding variable used in the spawned script.

Parameters that are passed into a script appear in that script's trace output in the Begin action.

Result Branch Conditions

Result branch conditions allow you to create branches in your script to handle different outcomes when an action executes.

Condition

Description

Default

Path taken unless the script meets a condition that requires it to take one of the other branches. It is also taken if the action's other branches are not defined.

Error

Path taken when the action fails to execute properly. For example, when there is an unexpected problem such as poor connectivity, syntax errors, and so on. The _ERR variable, with a single underscore character, should be populated with a condensed explanation of the problem.

Script Example

This is an example to show how this action can be used in scripts. It is not intended to be a complete script. Additional scripting may be required.

In the main script below (shown top), when the script is triggered, the Runsub action immediately triggers the subscript (shown bottom). In the subscript, Voiceparams sets the Text-to-Speech settings, and the Hours action sets branches for open, closed, and holiday to three different Return actions. When the subscript is finished, the values in the ReturnValues property (in the Return action) are stored in the ReturnVariable field (Runsub action in the main script). The Case action then sets the open, closed, and holiday branches as appropriate.

Main Script

An example script, showing Studio actions with arrows connecting them. Each action has a label beneath it to indicate what the action does in the script.

Would you like to download this script?

Subscript

An example script, showing Studio actions with arrows connecting them. Each action has a label beneath it to indicate what the action does in the script.

The three Return actions provide values in the ReturnValue property so the Case action in the main script can determine which branch to follow.

Would you like to download this script?