Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in RPA by (12.7k points)

I have several workflows in UIPath. What I'm wanting to do is: for a given flowchart, I want to execute those workflows in "random" order - but also not execute the same workflow twice.

For example, let's say I have 3 workflows. I put them all in the same flowchart.

When I click 'Run', I want UIPath to decide which one to run first, but after that one runs, I want it to decide between Workflow 2 and Workflow 3 - and not run Workflow 1 again.

Logically I don't know how to do this. I'm fairly new to UIPath so I don't have a lot of experience with variables, but I'm thinking the one approach might be to create a Boolean variable for each workflow and then after each one runs, I toggle the variable for that workflow. However, I don't know how to do that...

An alternative approach I can think of is to use a Switch (or multiple Switches) and set the expression to a random number between 1 and 3 using new Random().Next(1,3) - but then I still have the problem that it might run Workflow 1 twice. Is there a way to tell the Switch activity to execute all Cases in a random order?

1 Answer

0 votes
by (29.5k points)

 one way to go about it will be to make sure each workflow is moved to its own file then create a collection with all file names. Shuffle the list, iterate over it, and then invoke the workflow file.

Here's the code used in the Invoke Code activity,

Dim r As Random = New Random()
Dim list As New List(Of Int32)(New Int32() {1, 2, 3})
out_List = list.OrderBy(Function(a) r.Next()).ToList()

One benefit of this approach is that adding or removing workflow files simply requires changing the list, but no changes to the main workflow itself.hope this helps


Browse Categories