Skip to Content
Technical Articles
Author's profile photo Jerome GRONDIN

SAP Intelligent RPA 2.0 : How to reuse variables defined in a block

Hello bot builders !

 

With SAP Intelligent RPA 2.0 it is quite easy to build complex automations with lots of different “blocks” and “branches”. Ex :

Automation%20with%20many%20activities%2C%20including%20blocks%20and%20branches

In some cases, activities in these blocks produce a result that you would like to reuse in the rest of your automation. Let me show you how easy it is !

 

Problem description

Let’s say you have to implement a complex workflow, with lots of “blocks”.

– Oh wait ! What is a “block” ?

A “block” is a structure where you can encapsulate activities (except for screens). In Cloud Studio, when you open the Controls menu in the right side panel, you’ll see the following :

In this list, Condition is a block. For each is another block. Forever is a block. Repeat as well. Screen Switch too. And of course, the Try block.

To help you visualize it, let’s insert one of these elements in the canvas of an automation :

Do you see the light blue outline ? This is the block.

– So what ?

Now let’s say you create a variable in this block. See below :

The way the tool is designed prevents you to use the string variable outside of the block. This variable is what we call a scoped variable. This means it is only available in the scope of the condition block, and it has no existence at all outside of it.

– Wait ! What ? And what if I need to use this variable as an input parameter of an activity after the Condition block ? 

 

How to reuse the scoped variable ?

Using output parameters

For all the blocks you can use in the Cloud Studio, you can define an output parameter.

It’s up to you to define the name of this output parameter. And of course, you can define the value of this parameter for each branch of the block.

An example is worth a thousand words, so…

If we take again our Condition block, we must define a value for the 2 branches :

  • if the condition is met
  • if the condition is NOT met

As shown in the picture above, the output parameter will take 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 will be assigned to myOutputVariable. (as we left the field empty ; but it is also possible to define another value)

 

Another common example : I’m calling a web service within a Try/Catch block. Obviously, the result of the web service call might have some influence upon the whole automation. Let’s have a look :

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

If the web service call succeeds, myOutputVariable will take the value of obj. Otherwise, the error object will be assigned to it.

But in both cases, I’ll be able to display the result in the logs, as myOutputVariable is available outside of the block.

Using ‘global’ variables

Another way to deal with this issue would be to create a variable outside of a scope, and then assign it a value in the block where you need to.

Ex:

 

Conclusion

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

By using ‘global’ variables, you can assign values in the branches of the block.

 

Now it’s up to you to decide what method you want to use !

 

Find more information on SAP Intelligent RPA:

Exchange knowledge: SAP Community | Q&A | Blog

Learn more: Webinars | Help Portal | openSAP

Explore: Product Information | Successful Use Cases

Try SAP Intelligent RPA for Free: Trial Version | Pre-built Bots

Follow us on: LinkedInTwitter and YouTube

 

Assigned Tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.