Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
2,054
This is a submission for the SAP Intelligent RPA Tutorial Challenge.

This blog post will let you know how you can Fetch Variables from SAP Intelligent RPA Cloud Factory and use data in your process bot.


Cloud Factory Variables is useful to store deployment settings, environment details while running bot either in Attended or Unattended Mode.


There are 3 types of variables Cloud Factory Supports :

  • Text

  • Hierarchy

  • Credential


To start with There are 2 Steps :

Step-1 : Create Variables in SAP Intelligent RPA Cloud Factory.

Step-2 : Code to Fetch Variable from SAP Intelligent RPA Cloud Factory.

Step-1 : Create Variables in SAP Intelligent Cloud Factory


For that you need to have access to SAP Intelligent RPA Cloud Factory.


1.  Login to SAP Intelligent RPA Cloud Factory

2. Click on Management Tab



3. Click on Environment

4. Search for your Environment



5. Click on New Variable Button on the top-right corner.



6. Enter Name, Description and Type of Variable

Now w.r.to type there are 3 types of variables you can create :

  1. Text

  2. Hierarchy

  3. Credential


In Text type you store data such as System URL, Excel File Path, OData Service or information which is required for every bot run.



In Credential Type, you can store System Credentials or in case of SAP S/4HANA System we can use it to store Communication Username and Password.



Now we created 2 Variables in SAP Intelligent RPA Cloud Factory

  • System Credentials

  • System URL




Now next we are going to learn how to write code in a process bot to read these variables.

 

Step-2 : Code to Fetch Variable from SAP Intelligent RPA Cloud Factory

1.Create a Project



2. Create a Workflow with Custom Step and Build the Project



Next you need to go to Source Code Section and you will see the below code generated after you did a build.
GLOBAL.events.START.on(function (ev) 
{
systray.addMenu('', 'Fetching_Cloud_Factory_Variables', 'Fetching_Cloud_Factory_Variables',
'',function (ev)
{
var rootData = ctx.dataManagers.rootData.create();
GLOBAL.scenarios.Fetching_Cloud_Factory_Variables.start(rootData);
});
});

/*
Scenario: Fetching_Cloud_Factory_Variables
*/

GLOBAL.scenario({ Fetching_Cloud_Factory_Variables: function(ev, sc)
{
var rootData = sc.data;
sc.setMode(e.scenario.mode.clearIfRunning);
sc.setScenarioTimeout(600000);
sc.onError(function(sc, st, ex) { sc.endScenario(); });
sc.onTimeout(300000, function(sc, st) { sc.endScenario(); });
sc.step(GLOBAL.steps.Fetching_Cloud_Factor);
}},ctx.dataManagers.rootData).setId('5c310ba0-c652-4220-86e0-807e4ea29b72') ;

GLOBAL.step({ Fetching_Cloud_Factor: function(ev, sc, st)
{
var rootData = sc.data;
ctx.workflow('Fetching Cloud Factory Variables', '327b51fa-07c9-43c9-bd8c-55eeb996191f');

/*
Here you will Write Code to Fetch Cloud Factory Variables
*/

sc.endStep();
return;
}
});

 

Now in the the above code a Custom Step will be created i.e. “Fetching_Cloud_Factor”, in that we are going to write a code that will fetch Variables from Cloud Factory.

We are going to use ctx.setting, Now what is ctx.settings ?

ctx.settings is a function mainly used to update the deployment settings of an application to the particular environment

It offers 3 Functions

  • a function to set the value of a setting;

  • a function to get the value of a setting;

  • a function to clean the cache of a setting.


A setting is defined by a data pair: a name and a value.

A setting can be linked to a particular environment, by default, it is available for all environments.

By default, a setting is stored in clear text on the Factory server. But it could be encrypted. In this case, the encryption key to use must be specified using ctx.cryptography.keys

So now let’s use ctx.setting to read value from Cloud Factory

 

First, we will set the declaration



 /*Declaring Setting for System URL*/
var settingDeclaration = {};
settingDeclaration["System URL"] =
{
key: ctx.cryptography.keys.none,
server: true
}
ctx.setting(settingDeclaration);

/*Declaring Setting for Credential*/
var credDeclaration = {};
credDeclaration["System Credentials"] =
{
server: true
}
ctx.cryptography.credential(credDeclaration);

 

And then we will read the Variables
ctx.settings["System URL"].get(function (code, label, setting) 
{
if (code === e.error.OK)
{
ctx.log(setting.value);
}
else
{
sc.endScenario();
return;
}
});

ctx.cryptography.credentials["System Credentials"].get(function (code, label, credential)
{
if (code === e.error.OK)
{
sc.localData.cred =
{
username : credential.userName.get(),
password : credential.password.get()
}
ctx.log("Username: " +sc.localData.cred.username);
ctx.log("Password: " +sc.localData.cred.password);
}
else
{
sc.endScenario();
return;
}
});

 

Finally Run the Code and you will find the Output Log in the Debugger as shown below :



Remember retrieved data must be displayed only in the debug mode. Never in other modes, else it’s a big security breach.

 

To summarize, we understood how to fetch Text Type and Credential Type variables from SAP Intelligent RPA Cloud Factory and use it in the process bot.

You can use SAP Intelligent RPA Cloud Factory Variables to store details such as :

  • Root System URL's,

  • API(OData, SOAP Service Endpoints),

  • Name of CDS View,

  • System Credentials,

  • Communication User (in case of S/4HANA System),

  • Mailbox Location,

  • Email-ID's,

  • Boolean or Numeric Values that might be required

  • Excel Location

  • Folder Location,etc

  • Timeout value for a process bot,

  • Sleep or Wait Values,

  • Global Messages, etc.


 

Try this out, let me know in the comments if you face any challenges.

Happy to help !!!
1 Comment