Use Of Invoke Workflow File And Arguments In UiPath

UiPath is one of the leading RPA tools now. Working in UiPath Studio is really interesting. 

In this article, we will learn about how to use Invoke Workflow File activity in UiPath Studio. 

Invoke Workflow File activity helps to build fragments of a project in separate workflow files (.xaml file) and call them in place where they’re needed (e.g. Main.xaml workflow). 

We can pass values to/from the other workflow in this way. 

Before we go into step-by-step approach, let's talk a bit about Variables and Arguments 

Ideally Variables and Arguments both hold values of different types (e.g. Generic value, text, number, data table, object, Boolean etc.). The main difference that we need to focus here is: a variable stays within its own workflow where it is created, whereas an argument has an extra property (i.e. Direction), which allows it to pass the value between workflows (IN, OUT, IN/OUT). 

Let's get started with the processes where we will be using Invoke Workflow File activity and learn a bit more about variables and arguments for a simple process. 

Step 1

Open UiPath Studio 

From the Start menu, find Process under New Project column. Click to create a new process. 

Use of Invoke Workflow File & Arguments in UiPath

Step 2

Write a Name and an optional Description for the process. 

Click Create 

Use of Invoke Workflow File & Arguments in UiPath

Step 3

In the following window we will find the main workspace for the project. 

Click on Open Main Workflow 

This is the place where everything happens. 

Use of Invoke Workflow File & Arguments in UiPath

Step 4

First, we will take two number input. For that we will need something to collect input from the user. 

From the Activity panel below, search for Input Dialog activity. 

Drag and drop two Input Dialog activity to the main sequence. 

Use of Invoke Workflow File & Arguments in UiPath

Step 5

Now, from the variable and argument panel we will create one variable of type integer (Int32), let's name it result and from the argument panel we will create two arguments of type integer (Int32), let's name them num1 and num2. The direction of these two arguments will be Out, as we will be sending these values OUT to another workflow file. 

Use of Invoke Workflow File & Arguments in UiPath

Step 6

At this stage we will configure our two Input Dialog activities to receive user input. 

The Input Dialog activity allows user to provide input which captured in the variable or argument mentioned in the Value entered field. 

Use of Invoke Workflow File & Arguments in UiPath

Step 7

Once we have our desired input in place, we will now create an additional workflow file where we will be processing our input values and get the result from. 

Click on New button on the Ribbon. 

Select Sequence 

Write a name for the new sequence. Let's name it Process

Click Create 

Use of Invoke Workflow File & Arguments in UiPath

Use of Invoke Workflow File & Arguments in UiPath

Step 8

In the newly created Process.xaml file is now ready for next stage. 

Here, we will create three arguments of type integer (Int32) from the Arguments panel. We will be needing two arguments with direction as IN, to receive the values (num1 and num2) from the Main sequence. 

We will also need one argument with direction as OUT, to pass the final value from the Process to Main

The naming convention for arguments is to use prefix IN or OUT with the name to avoid directional confusion. 

Therefore, our arguments are as follows: IN_value1, IN_value2, OUT_solution 

Use of Invoke Workflow File & Arguments in UiPath

Step 9

After creating the necessary arguments, let’s drag and drop two Assign activity from the Activity Panel on the left. 

We will simply first Add the two numbers and then perform a simple Modulo operation on the total. 

For our first Assign activity, the command is: 

OUT_solution = IN_value1 + IN_value2 

And for the second Assign activity, the command is: 

OUT_solution = OUT_solution MOD 2 

This will divide the total of two numbers by 2 and return any remainder as integer (Int32) 

Use of Invoke Workflow File & Arguments in UiPath

Save the workflow from the Save button on the Ribbon or press Ctrl+S  

Use of Invoke Workflow File & Arguments in UiPath

Step 10

Back in the Main workflow, get the Invoke Workflow File activity from the Activity Panel. 

Use of Invoke Workflow File & Arguments in UiPath

Click on the folder icon to locate and attach the Process.xaml workflow file. 

  Use of Invoke Workflow File & Arguments in UiPath

Alternatively, we can directly drag and drop the Process.xaml file to the Main sequence from the Project panel on the left. 

Use of Invoke Workflow File & Arguments in UiPath

Step 11

Once the Process.xaml file is invoked, we will now bind the arguments of both the workflows together so that the user input values can be passed to another workflow. 

Click on Import Arguments button. 

The following window shows the list of arguments in the Process workflow. The directions are respective to the Process workflow. 

We will now assign num1 and num2 for the values of IN_value1 and IN_value2 respectively. 

We will receive the value of OUT_solution into our local variable result which we created at Step 5. 

Use of Invoke Workflow File & Arguments in UiPath

Step 12

Now the final value is back in the Main sequence into the result variable. We will show the result in a Message Box pop-up. 

Drag and drop a Message Box activity after the Invoke Workflow File activity. 

Insert the display text as String

"The result is: " + result.ToString 

As our result variable is an integer, the Message Box won’t be able to show it as text, therefore, we used the ToString formula to convert the integer to String. 

Use of Invoke Workflow File & Arguments in UiPath

Step 13

All the steps are done. It’s time to run the project. 

Click Run from the Ribbon or click Ctrl+F5 

Use of Invoke Workflow File & Arguments in UiPath

Insert two numbers in the Input Dialog boxes, one after another. 

Use of Invoke Workflow File & Arguments in UiPath

Click Ok and get the final output in the Message Box 

Use of Invoke Workflow File & Arguments in UiPath

Summary

We have created two sequences and passed some values from one sequence to another with arguments. Then we have done some calculation processing with the values and finally passed the output to the Main workflow. In this article, we have seen how to Invoke a workflow file and how to set arguments for the invoked process. 

Happy Automation.


Similar Articles