Robotic Enterprise Framework in UiPath

Robotic Enterprise Framework is a project template based on State Machines.

  • Re-Framework is a Template which provides all the required basic needs of any process automation.
  • Like reading and storing the config data.
  • Close all the unnecessary applications.
  • Open the required applications.
  • Get the Transaction and Process it.
  • Retrying the transaction if required and logging the status of all processed transactions, Failed or successful.
The Features of Re-Framework:
  • Proper Exception handling
  • Recovery abilities
  • Effective Logging
  • Reusability...etc..

Re-Framework Architecture

The Re-Framework has a main. xaml file, which uses the state machine workflow. It is used for a better presentation of the process flow.

The Main.xaml file is designed with the state machine. And it is prepared with the three state activities and 7 Transition. Each state has been connected with the transaction.

Re-framework architecture has four states :

  • Init : This is the Initial state, which is used to read and store the config data in a dictionary. Closes all the applications and Opens the required application. If Init passes successfully, then the robot moves to the next state.
  • Get Transaction Data: It is a data retrieval mechanism. Used to get the transaction from Queue, Data table, Database, Folder, etc..If it has a new transaction item, it goes to the next state.
  • Process Transaction : It is used to Process the transactions fetch from, get from the previous state. If there are no records to process, then the robot moves to the end process state.
  • End Process: It ends the robot successfully and then closes all the application and kill the apps.

re-frame-aechitecture-rpa-uipath

RE-Framework is created to fit all of the best practices regarding logging, exception handling, application initialization, and others, being ready to tackle a complex business scenario.

The template contains several pre-made State containers for initializing applications, retrieving input data, processing it, and ending the transaction.

All of these States are connected through multiple Transitions which cover almost every need in a standard automation scenario.

The default dependencies in a Robotic Enterprise Framework project are:
  • UiPath.Credentials.Activities
  • UiPath.Excel.Activities
  • UiPath.Mail.Activities
  • UiPath.System.Activities
  • UiPath.UIAutomation.Activities.

Real-time Example for the Re-Framework

This example demonstrates getting orders from Amazon. This example also explains how to implement Re-Framework for our business requirements.

Open the UiPath Studio home and then select Robotic Enterprise Framework

robotic-enterprise-framework-rpa-uipath

Create a New Robotic Enterprise Framework
new-robotic-enterprise-framework-rpa-uipath

Once it is opened in the UiPath Studio, it looks as shown below. The Re-framework is based on State Machine, and it contains four states as Init, Get Transaction Data, Process Data, and End Process.
re-frawork-architecture-rpa-uipath

Next, click on any of the activities and then click on the Variables pane, you will find some of the global variables which are created by the template itself.
global-variables-rpa-uipath

Where Init state which reads all the data from the config file. Go to the Project Pane and then click on the Data you will find the Config file.
config-file-rpa-uipath

Clikc on the Config.xlsx file, Once it is open, it looks as below
config-xlsx-file-rpa-uipath

Now I am going to add below details in the config file
after-adding-variables-and-values-rpa-uipath

Where the loginurl is the basic URL instead of the variable, we have created that in our config file, a this will be read from here. And amazonlogin is the name, however, and if you are connected with assets in orchestrator, then it looks for a name called amazonlogin; if it is not connected, then it prompts for Userid and logs in.

Output_file is an output file after scraping the data it will take the data to the output.xlsx and next is the year it will ask the user to which year you want to scrape the data.

Like this, you can create your variables and values directly in the config.xlsx which can be used throughout your re-framework.

Init State:

Click on the Init State and then Once the Init state as opened in the UiPath Studio then double click on the if first run-read config file.

if-first-run-read-config-file-rpa-uipath

Once it is opened, scroll down to Invoke KillAllProcesses.xml and then click on the Open Workflow

kill-all-processes-workflow-rpa-uipath

Next, the Kill Process activity will be opened as shown below
kill-process-activity-rpa-uipath

Add Kill Process activity inside the Kill Process and click on the Kill Process activity and add the process name as iexplorer in the Properties Pane, as shown below.
kill-process-activity-and-process-name-rpa-uipath

Close the Kill Process and then move to the Invoke InitAllApplications workflow

invoke-init-all-application-rpa-uipath

Click on the Open Workflow to Open the Invoke InitAllApplication workflow, Once it is opened, it looks as shown below.
innit-all-application-sequence-rpa-uipath

Create a new sequence to work on the browser, I am creating a new sequence called OpenIE_explorer_Example

new-sequence-open-ie-explorer-rpa-uipath

Once the sequence opened in the UiPath studio, then add Open Browser activity inside the sequence.
open-broser-activity-inside-the-openie-explorer-rpa-uipath

Click on the Open browser and then create a new argument in the Argument pane. And then enter the argument type asSystem.Collections.Generic.Dictionary<TKey, TValue>and then select the Tkey type as String and TValue type as Object

dictionary-generic-argument-type-rpa-uipath

argument-pane-openie-rpa-uipath

Next, enter the URL which we are going to get the amazonurl from excel via in_config file written asin_config("amazonurl").ToString
url-of-the-amazon-rpa-uipath

Next, Open the Amazon login page in the browser and then go to UiPath Studio and add Click activity inside the Do Container of the Open browser.

click-activity-inside-do-container-of-the-open-browser-rpa-uipath

Next, Click on the Indicate element inside browser and click on the Sign-in button in the amazon login page in the browser.
scraping-sign-in-button-rpa-uipath

Next, add one more Type Into activity inside the Do Container and then scrape the Email or phone number page as shown below. Click on the Do Container and create a new variable as userid and password in the Variables pane

creating-userid-and-password-var-rpa-uipath

type-into-for-user-id-rpa-uipath

After entering the email or phone number you need to click on the Continue button, for that add Click activity, and then indicate the Continue button on the browser.
scraping-continue-button-on-brwoser-rpa-uipath

Next, add One more Type Secure Text activity and then scrape the Password in the browser and then enter the password variable under Properties Pane for Secure Text Property and also set the type of the password variable to secure.security.securestring

set-password-var-type-to-secure-string-rpa-uipath

type-secure-text-rpa-uipath

Next, add Click activity and then scrape the Login button on the browser

sccraping-login-button-rpa-uipath

Once we login to the Amazon we need to order the items, so Add Click activity and then scrape the Order section as shown below.
scraping-orders-section-rpa-uipath

Add Click activity and then scrape past 6 months button under Orders
past-six-month-button-under-orders-rpa-uipath
uipath-click-activity-scraped-past-six-month-rpa-uipath

  • Now add Click activity into the Do Container and then,
  • Click on the Indicate element inside browser and then place the cursor on the past 6 months
  • Press Ctrl+F2 to select the year from the drop-down
  • Select the year from the drop-down and wait until the time zone ends
  • Then select the 2017 year and scrape it.
    select-year-2017-rpa-uipath
  • Click on the three horizontal lines(Hamburger) and then select Open in UiExplorer
    open-in-ui-explorer-rpa-uipath
  • Once it is opened in the Ui explorer, then click on the Indicate element and then select 2017 in the browser.
  • Next, unselect id and then select aaname and then copy the below code and click on save.
    indicate-element-and-save-rpa-uipath
  • Click on the Click Activity which has scraped 2017 year and then go to the Selectors in the Properties pane, to manipulate the aaname value as shown below.
    <html app='chrome.exe' title='Your Orders' />
    <webctrl tag='A' aaname="+in_config("year").ToString+"/>
  • Go to the Project pane and then select GetAppCredentials under Framework
    get-app-credentials-under-framework-rpa
  • Next, add Invoke GetAppCredentials workflow activity inside the Do container and before the email scraping click activity.
    get-app-credentials-rpa-uipath
  • So we are going to get the userid and password from the Orchestrator or from the User during the running the program.
  • If Orchestrator is connected then we are going get the userid and password from the asset credentials with the name which we have defined in our excel.
  • In the Excel file, we defined as Amazon credentials
  • Now we have to pass the arguments, so click on the Import Arguments and then
    passing-arguments-rpa-uipath
  • Now go to your InitAllApplications workflow and drag and drop the OpenIE_Explorer_Example sequence.
    add-openie-explorer-example-workflow-inside-init-all-application-rpa-uipath
  • And then click on the Import Arguments and then pass the argument In_config which passes all the configuration related data to our OpenIE_Explorer_Example sequence as shown below.
    pass-in-config-parameter-rpa-uipath
  • Now, we have done all the initializations.
  • Now, let us go to the Invoke KillAllProcess workflow and the open the workflow and then add Path Exist activity inside the Kill Process.
  • And add in_config the argument in the argument pane and then enter the path to the file as shown below.
    add-in-config-file-rpa-uipath
    path-exist-activity-rpa-uipath
  • Click on the Path Exists and then create a new variable called existfile in the Properties Pane for Exists Property.
    exist-file-rpa-uipath
  • Next, add If Condition after the Path Exist activity in the Kill Process and write the condition as shown below.
  • Add existfile variable inside the if Condition and then enter the path of the variable(in_config("output_file").ToString) in the properties pane for path property
  • And also add Delete activity inside the Then condition block
    if-condition-activity-inside-kill-process-rpa-uipath
  • Next, go back to the Invoke KillAllProcess and then click on the Import argument and then pass the value
    invoke-workflow-argument-rpa-uipath

So We have completed our initialization part.

Transaction State:

Now, let us go to the Get Transaction state. If you see the Transaction variable in the variable, the variable type is of QueueItem.
transaction-variable-rpa-uipath

So here we are not using Orchestrator so we can change the variable type to String.
trasaction-variable-type-to-string-rpa-uipath

As soon as you set the Transaction variable type to String you will find many errors across the workflow because it has been passed as QueueItem in many locations.
errors-in-workflow-rpa-uipath

Double click on the Get Transaction Data

get-trasaction-workflow-rpa-uipath

We are not going to assign anything to the string, so these are temporary errors, Just click on the TransactionItem on the End process and cut it then paste it in the same place so the error will go.
end-process-with-no-erroe-rpa-uipath

Next, click on the Invoke GetTransactionData Workflow and then click on the Open Workflow and then open the Variable pane, and wherever you will find the Transaction variable set the variable type to string.

When you click on the Import Argument on the Invoke GetTransactionData Workflow you need to freshly enter the argument because we have changed the variable type to string.

And even you need to traverse through Try Catch exception and then just cut and paste the Transaction variable after you do not see any errors.
try-catch-exceptions-without-error-rpa-uipath

And we still have an error in the Process Transaction, and then click on the Open Workflow under Invoke Process Transaction workflow.

invoke-process-trasaction-workflow-rpa-uipath

Once you open the workflow, you will find Process Transaction activity, click on the Process Transaction and then open the arguments in the Arguments Pane and then set the In_Transaction argument type to String.

In the same way, traverse through Try Catch and Finally block and set the Transaction variable type to string.

Now we have removed all the errors which occurred in the Workflow. Now go back to the Invoke GetTransactionData Workflow and then comment out the Get TransactionItem activity as shown below.
get-transaction-item-comment-out-rpa-uipath

Next, Go back to the Process Transaction state. Double click to open it. Add Attach Window activity inside the Process Transaction
add-attach-windows-activity-rpa-uipath

Next, click on the Indicate window on-screen and then indicate the order history page on the browser.

State Machine in UiPath

A state machine is a concept used in designing computer programs or digital logic.

  • There are two types of state machines: Finite and infinite-state machines
  • The former is comprised of a finite number of states, transitions, and actions that can be modeled with flow graphs, where the path of logic can be detected when conditions are met.
  • A state machine is any device storing the status of something at a given time.
  • The status changes based on inputs, providing the resulting output for the implemented changes.
  • A finite state machine has limited internal memory.
  • Input symbols are read in a sequence producing an output feature in the form of a user interface.
  • State machines are represented using state diagrams.
  • The output of a state machine is a function of the input and the current state.
  • State machines play a significant role in areas such as electrical engineering, linguistics, computer science, philosophy, biology, mathematics, and logic.
  • They are best used in the modeling of application behavior, software engineering, design of digital hardware systems, network protocols, compilers, and the study of computation and languages.
  • The operation of a state machine begins from a start state.
  • On a successful transition, it ends up in an accept state.
  • The transition takes place based on the inputs provided.
  • The current state depends on the past state of the system.
  • The number of states formed depends on the available states of memory.
  • A transition is enabled based on certain conditions and indicates a state change.
  • An action describes an activity performed at the given moment.
  • The different types of actions are transition action, input action, entry action, and exit action.
  • Deterministic automata have exactcharacteristics within them.
  • They include additional concepts such as orthogonal regions and hierarchically-nested states.

Real-time example of State Machine in UiPath

Create a new process called Static_Machine_Examples

static-machine-example-process-rpa-uipath

In this example, we are considering Lift as a real-time example for Static Machine.

  • If a lift is on the 1st floor, then it will go to either the ground floor or the 2nd floor.
  • If Lift is on the ground floor, then it will go to the 1st floor.
  • Let us take it as the Initial state is the 0th floor, which is nothing but an Initialization.
  • The second state is getting people inside the Lift, which is nothing but a Get Transaction.
  • Once the people are in, then the Lift moves from one floor to another floor, which is nothing but a Processing state.
  • Once the Lift moves to the 11th floor, then it is the final floor and which is nothing but a Final state.
  • Now, go to UiPath Studio, search for State Machine in the activity panel.
    state-machine-activities-rpa-uipath
  • Next, add State Machine activity inside the sequence.
    add-state-machine-activity-inside-the-sequence-rpa-uipath
  • By double-clicking on the State Machin, you will find the Start button.
    start-button-in-side-the-state-machine-rpa-uipath
  • Next, add Three-State activities inside the State Machine activities, as shown below. If you need, you can also change the name of the state, as shown below.
    add-state-activities-inside-the-state-machine-rpa
  • Next, add Final State Activity inside the State Machine activity.
    complte-workflow-of-state-machine-rpa-uipath
  • Connect each of them by drawing a line between each activity.
    connect-each-activities-by-drawing-line-rpa-uipath
  • In the below image, you can see the Transition numbers T1, T2, and T3. Transitions happen when we are moving from one state to another state. In Transitions, there are conditions.
  • If we want to move from getting people to moving state, then this transition happens only when the people less than 10.
  • If there are more than ten people, then the transition won't happen.
  • That means moving from one state to another state is based on the transition condition.

tansition-numbers-rpa-uipath

  • If you click on any transition, you can see the condition, where the transition is happening from source Initial to the Destination Get People.
    transition-source-and-destination-rpa-uipath
  • Now let us go to each state and have a closer look, you can see that each state is having Entry, Exit, and Transition state.
    entry-exit-transition-rpa-uipath
  • When you run the transition, the Entry state of each activity will run first, and then the Exit state of each state will be run next.
  • Next, click on the State Machine activity and then create a variable shown below.
    creating-a-variable-in-state-machine-rpa-uipath
  • Click on the Initial State activity and add Write Line activity inside the Entry State in the Initial activity.
  • Add Assign activity inside the Entry State and enter the condition, as shown below.
    write-line-and-assign-activity-inside-entery-of-initial-activity
  • Next, add Write Line activity inside the Exit state of Initial activity.
    write-line-activity-inside-exit-state-of-initial-rpa-uipath
  • Next, click on the Get People activity and add Input Dialog activity inside the Entry state of the Get People activity and write the condition as shown below.
  • Click on the Get People activity and enter the variable name Num_Of_Customers in the Result Property under Properties Pane.
  • And also, add Write Line activity inside the Entry state of the Get People activity.
    entry-state-pf-get-people-activity-rpa-uipath
  • Add Write Line activity inside the Exit state of the Get People activity, as shown below.
    write-line-activity-inside-the-exit-state-of-get-people-activity-rpa-uipath
  • Next, click on the Moving activity and add Assign activity inside the Entry State and then create a new variable inside the Assign activity.
  • And then add While activity inside the Entry state of the Moving activity.
    assign-and-while-activity-inside-the-entry-of-moving-activity-rpa-uipath
  • Next, add a sequence inside the body of the while activity and then add Write Line activity and Assign activity inside the sequence and write the conditions shown below.
    body-of-the-while-activity-rpa-uipath
  • Click on the Exit state and add Write Line activity and enter the text as follow.
    write-line-activity-in0exit-state-of-moving
  • Next, click on the Final State activity and add Write Line activity inside the Entry State, as you can see only the Entry State in the Final Activity.
    final-state-with-write-line-rpa-uipath
  • Clikc on the T2 Transition and write the condition for the same as shown below.
    condition-in-transition-t2
  • And if the customer number is greater than 10, then we cannot be able to move from one floor to another floor, so create another transition called T4 in the Get People activity and write the condition for the same.
  • Next, add the Message box inside the Action and write the text, as shown below.
    t4-transition-condition-rpa-uipath
  • Save and Run the sequence, After the execution, Enter the Number of People pop-up message will occur, enter the number of your choice and then click on ok.
    enter-number-of-people-rpa-uipath
  • Now I am entering eight and click on ok, and then it will execute the workflow.
    entering-less-than-ten-rpa-uipath
  • If Enter number Greater than ten, then I am going to get the below message.
    entering-greater-than-10-rpa-uipath
    cannot-move-msg-rpa-uipath
  • If you click on the Ok button, then it will again ask you to enter the number.
    again-asking-to-enter-number-rpa-uipath