Nintex Workflow – Generate Random Numbers Using Nintex UDAs

Posted by Vadim Tabakman Wednesday, March 11, 2015 8:44:00 AM Categories: Loop Math Calculations Nintex Workflow Nintex Workflow 2013 Random Regular ExpressionUser Defined Actions

Sticking with the No-Code standard, I really wanted an out-of-the-box way to generate random numbers using Nintex User Defined Actions (UDAs).  Some of you may have seen a previous post I did which connected to an SQL server to accomplish this task.  But that method requires some SQL connectivity, which not all users have. We want a solution consistent with Nintex’s motto, “Workflow for Everyone.”  

Another solution would be to build an Inline function for Nintex Workflow.  That task would actually be quite easy. You could do so with code and write your own C# and deploy the assembly.  But again, that approach requires development skills, and the need to convince your SharePoint admin to deploy a solution to your farm.

But while tinkering around the other day, I found another way I could generate random values.  Granted, it’s not elegant. Not even remotely. But it does work. I’ve run it through a bunch of tests, even with extremely large numbers, and get successful results each time.

Since there’s no Random action or fn-Random Inline function, here’s a wacky way to create a random number generator as a Nintex UDA.

Writing UDAs to Generate Random Numbers Using Nintex

First, the User Defined Action will need to take two parameters:

  • The first is a number that specifies the limit of the random number set.  So, if you want a number between 0 and 9, you set this number at 10 (this is the count of the numbers we can use).
  • The second parameter is an output parameter, which is the random number.

generate random-numbers-using-nintex

I had an epiphany!

I can use an Inline function called fn-NewGuid().  This function returns a Guid. For readers who don’t know what a Guid is, it looks something like this:

 3F2504E0-4F89-41D3-9A0C-0305E82C3301.

(You can find more information here – What is a Guid?)

Each Guid is unique. That’s the whole point of using them.  If you noticed, the Guid in the example above is made up of numbers, alpha characters and dashes.  If you remove all the alphas and dashes, you’re left with a large number.  That’s what I use to start my random number calculation.

So, taking out the unnecessary characters in the example above, we end up with:

325040489413900305823301

Now that we have this number, we need to look at the max number count we are looking at (10).  We figure out how many characters it is – in this case two –  and we pull out that many characters from our Guid number –> 32

We then take that number, and perform a MOD (MODular arithmetic): 32 mod 10 = 2

There’s our random number.

If our Guid number were 93829392823, we’d do a 93 mod 10 = 3

I know, I know. This is a little confusing.  But it works. It generates random numbers using Nintex UDAs. Trust me.

I won’t go through the actions in the UDA, because the process above pretty much explains it.  But here is what the Nintex UDA looks like :

Screenshot_052716_071612_PM

Now you see the UDA, but how do you use it? Once you have downloaded the UDA below and published it, you’ll be able to use it with any of your workflows.  Simply drag the UDA onto the workflow, open it up, and put in the value you want and a variable to store the random number generated using the Nintex UDA.

generate random numbers using nintex

I created a workflow that not only shows how to use the UDA but also runs it 20 times so we can test it to make sure we get the results we want.

generate random numbers using nintex

It’s not complex.  We have a Loop action that iterates 20 times.  Inside is a Math Calculation that increments the number for the Loop and the UDA that generates the random number.  Finally, a Log action logs the random number.

I hope this Nintex tutorial helps those of you who want to generate random numbers using Nintex UDAs. Why not share the benefit of your experience with the rest of us, or ask further questions, in the comment section below?

Evoke Technologies & Nintex: Bringing Advanced Workflows to Businesses

Evoke Technologies is a premier partner with Nintex, the world’s leading SharePoint workflow firm. Our relationship with Nintex equips our clients to bridge the gap between existing Nintex Workflow for SharePoint features and their most pressing business needs. Nintex Workflow for Office 365 allows users to create SharePoint workflows easily.

Call Evoke Technologies today at +1 (937) 202-4161 (Select Option 2 for Sales) to continue exploring how automated workflow solutions for everyday business challenges, optimized in an Evoke Partnership, can benefit you.