Recently I needed to create a schedule of dates, one week apart. I created a loop and added 7 days in each iteration. I noticed it took a very long time, so I added a Log in History task in the loop and saw that each iteration was taking 5 minutes. I realized that this was down to ‘Safe Looping’.
This protective feature places some safety measures against the hazards of an infinite loop by adding a hidden delay..
I didn’t want to disable this option, mainly because of the maintenance overhead involved, so I looked for another option.
I realised that the Collection iteration (For Each) didn’t have any such restriction, so all I needed was to create a collection with the number of entries that I wanted to loop for.
The Regular Expression task with the Split operator is the easiest way to create a collection; it simply splits text based on a character. All I had to do was to create a string with the right number of delimiters.
This is where I got the idea for this article https://community.nintex.com/community/build-your-own/blog/2018/06/08/nintex-string-repeat.
Now, as n delimiters will create n+ 1 entries, we need to reduce the number of delimiters by 1
Initialising the string to a non-delimiter will ensure that the string is padded to length ‘Iterations’ containing n-1 delimiters.
Regular Expression
For each
We place the retrieved value in TempStr variable and ignore it.
Calculate date:
Here’s where we add the recurrent +7 days added on each loop
The final workflow
I set the Iterations variable to be a startup parameter and set it to 10
Here are the results from the history - as you can see, it all executed immediately
Time | Event | Message | ||
11/05/2018 10:49 | Workflow Comment | MyDate=18/05/2018 10:49 | ||
11/05/2018 10:49 | Workflow Comment | MyDate=25/05/2018 10:49 | ||
11/05/2018 10:49 | Workflow Comment | MyDate=01/06/2018 10:49 | ||
11/05/2018 10:49 | Workflow Comment | MyDate=08/06/2018 10:49 | ||
11/05/2018 10:49 | Workflow Comment | MyDate=15/06/2018 10:49 | ||
11/05/2018 10:49 | Workflow Comment | MyDate=22/06/2018 10:49 | ||
11/05/2018 10:49 | Workflow Comment | MyDate=29/06/2018 10:49 | ||
11/05/2018 10:49 | Workflow Comment | MyDate=06/07/2018 10:49 | ||
11/05/2018 10:49 | Workflow Comment | MyDate=13/07/2018 10:49 | ||
11/05/2018 10:49 | Workflow Comment | MyDate=20/07/2018 10:49 | ||