Intro

I recently worked on a project that required me to get creative and think outside the box, in order to provide the solution my client was looking for. After completing the project, I thought it would be something that other people might be interested in and was inspired to share how I created the process.

To give a bit of a background to this story –  I have a client that was looking to streamline their student enrollment lottery process. The “Lottery” process, which takes place each year, is used to randomly select a limited number of new students to be admitted to the school. Applications are submitted by potential students, the lottery is held on a specific date after the application deadline, applicants are drawn at random, and families are notified of their admission status after the lottery is complete.

The very first thing I needed for this process, was the ability to select users based on a numeric ID assigned to them at the time of enrollment. Typically, I would let SQL Server (or another database engine) create the number sequence – but in this case, the numbers were defined sequentially. Then, when it came time to select the random lottery winners, I would simply use a database function that would allow me to select rows at random. However, in this case – the project was being built in Laserfiche Cloud, which does not allow us to create those types of queries. Even if it did, I still wanted to have more control over the list that was to be returned. So, I decided to create a C# library – which was ran using a Laserfiche Remote Agent, on a local machine.

You can get information on setting up a remote agent here: Remote Agents | Process Automation | Laserfiche Cloud.

The Library

Overall, the requirements for my code were pretty simple. First, I needed to get back a list of random numbers. Second, I needed to be able to select the range from which the numbers would be chosen. For example, I only want a list of numbers between 1 and 100. Third, I want to set the number of results returned (How many winners?). Finally, maybe most important, no duplicate selections. So, I wrote and compiled the library to these specifications. One of the decisions that I made was to use a HashSet as the return object. This proved important; because a HashSet, by default, will not accept duplicate values, which satisfied one of my requirements. The other reason I chose a HashSet, will show its value later, when I talk about the workflow.

The Script

Once the code is written and compiled, I setup a “Script” in Laserfiche Cloud. I did this under the “Rules” section (Figure 1).

Figure 1

 

I was first asked to name my script. Keep in mind, just like any other development job, I wanted to give my script a good descriptive name. As you develop more scripts over time, good naming will help you navigate and understand (aka remember) what you did and why. Once I chose a quality name, I defined my script (Figure 2). First, I needed to pick my language and where the remote agent will find my library. Next, I enter the class name and method I created (RandomNumbers and GenerateNumber respectively). Lastly, I defined my input and output variables. Based on my specifications defined earlier, I create a variable for the number of results I expect (ExpectedReturnCount), the minimum number to start drawing (Min), and the maximum number from which to draw (Max). Finally, I define the output or return variable (RandomList).

Figure 2

 

Once everything is setup, I can test. When I click the “Test Script” button it will ask me to provide values for my input fields. For my first test, I will ask the script to return 10 results between 100 and 200 (figure 3).

Figure 3

 

When I click test, 10 numbers are returned between 100 and 200. You can see the first four results in Figure 4.

Figure 4

 

It might be clearer, if I show a smaller example. Assume I want to pick 3 numbers out of a hat and the hat contains pieces of paper with numbers 1 through 10 written on them. Then the following setup in Figure 5 would do just that.

 

Figure 5

 

And the result is Figure 6.

Figure 6

 

Now that everything appeared to be functioning with my script, I can create my workflow.

The Workflow

Having built and defined the script, even if it is a one trick pony, it’s time to put it to work. In this specific case, I need a workflow that makes lottery selections. Since this post is about the random number script and not building a workflow, I will just describe the parts that relate to the script. So, the first thing I do, is add the Run Script Rule task to my workflow (Figure 7) and select my rule name. As you can see from Figure 8, I didn’t take my own advice, and I gave my script a terrible name of Random.

Figure 7

Once the script is selected, I can define my input variables. So just like I did in my test, I can set my expected return count, minimum and maximum numbers. You can see in Figure 8 I used tokens for the some of the variables. Tokens are what makes the script so dynamic. I can define any number of results between any two numbers, and it can change based on workflow tokens.

Figure 8

Now, as I alluded to earlier, the return type I used in the script was very important and here is why. You will notice that in Figure 8, the return type is stringWhat it isn’t saying, is that the return type is a list of strings or a multi-value string token. Why is that important, you ask?  Well, now I can use the For Each Value object in workflow (Figure 9, 10) to loop through the results of my script. Meaning, I don’t have to parse a string or add any other processing to my results.

Figure 9

 

Figure 10

 

Wrapping Up

In this post, I used a C# library to create a random number generator for a lottery project. I hope this post provided some helpful information or inspired you to create solutions where they don’t exist otherwise. Over the last 20 years, creating solutions (not just technology) has been the favorite part of my job, whether it be for my employees or customers. If I can help you in any way or you have any questions, please reach out, I would love to help.

 

Success is founded in Logic & Modified through Innovation

Learn More

Hopefully you found the above post helpful or inspiring. At Modified Logic, we not only provide the highest level of Laserfiche support, implementation services, form design, workflow automation, and integrations – we specialize in custom solutions for our clients. Our focus is to guide our clients through each step of their Digital Transformation Journey, and custom developed solutions are needed to enhance Laserfiche’s already powerful functionality.

If you would like to learn more about this process, process automation, development or are looking to begin your Digital Transformation journey, please contact us at (833)813-2221 or email sales@modifiedlgic.com.

 

About Modified Logic

With over 20 years of experience, Modified Logic has a proven record of providing the highest level of support & exceptional services for Laserfiche clients across multiple different industries. From initial deployments and expansion initiatives, to providing responsive support & continuous maintenance – Modified Logic provides everything you need to ensure a successful Laserfiche implementation. Modified Logic also specializes in business process automation, custom integrations, and providing advanced Digital Transformation services through Robotic Process Automation (RPA), Business Intelligence & Analytics, and more

Contact Us

833.813.2221

130 N Preston Rd. Ste. 100, Prosper, TX 75078

Monday-Friday: 8am-5pm

Transform Today