0

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 hae 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?

SUMguy
  • 1,505
  • 4
  • 31
  • 61

1 Answers1

0

Here's one possible approach. Make sure each workflow is moved to its own file. Create a collection with all file names. Shuffle the list, iterate over it, and then invoke the workflow file.

My example uses Integers, but you can use Strings alike. Note that I initialized the list in the Invoke Code activity, but you can do that anywhere you like and pass the list as an In Argument.

Here's the code used in the Invoke Code activity, taken from here:

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.

Random Workflow Invoke

Wolfgang Radl
  • 2,319
  • 2
  • 17
  • 22