Reuse Variable Defined in Any Block

You can create complex automation using various blocks and branches in your automation workflow. In some cases, multiple activities inside these blocks produce results that you can reuse in the rest of your automation.

The following example of a complex automation displays various blocks and branches used in the automation.

About Block

A block is a structure where you can encapsulate activities (except for screens). In Cloud Studio, when you expand the Controls menu in the right-side panel, you can see the following list of controls:

In the controls list, each control such as Condition, For each, Forever, Repeat, Screen Switch, or Try is a block.

When you drag and drop a control into the workflow of your automation, you can see a light blue outline as a block. The following screenshot is an example of the Condition block.

Use Variable Inside a Block

When you use a variable inside any block, the tool will prevent you to use the variable outside the block. The variable is called Scoped Variable.

In the following example, you can see a string variable is used inside the condition block. The variable is only available inside the scope of the condition block, and it has no existence at all outside the block.

Reuse the Scoped Variable

You can reuse the scoped variable as an input parameter of an activity after the block in two ways:

  1. Using Output Parameters

  2. Using Global Variables

Using Output Parameters

By using output parameters, you can access to variables which are defined inside a block. At the end of each block, you can check the value of the output parameter to determine whether the bot run through the main branch or through another one.

You can define the name of the output parameter and the value of the parameter for each branch of all the blocks that you use in the workflow of your automation.

Example 1:

In the following example, a variable is defined inside the Condition block.

In the Condition block, the value is defined for the two branches:

  • if the condition is met

  • if the condition is NOT met

The output parameter takes the value of the variable stringVariable (defined in the branch true of the condition block) if the condition is met during the execution of the automation. If the condition is not met, then no value is assigned to myOutputVariable. Therefore, the field is left empty; but it is also possible to define another value to the field.

Example 2:

In the following example, a web service is called inside the Try/Catch block.

If you want to display the result of the web service call in the Log Message activity, you must define an output parameter for the Try/Catch block.

If the web service call succeeds, myOutputVariable takes the value of obj. Otherwise, the error object is assigned to it.

In both the cases, you can display the result in the logs as myOutputVariable is available outside of the Try/Catch block.

Using Global Variables

By using global variables, you can create a variable outside the scope of a block, and then assign it a value inside the branches of the block.

Example:

In the following example, a variable is defined outside the Try/Catch block. You can assign a value to the variable inside the branches of the Try/Catch block.