cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
rogerb
Nintex Newbie

How Do I Use For-Each With Regular Number Variable

Jump to solution

I have a workflow with a loop that is working, but the loop takes far too long. I want to instead use a For-Each, but that uses a collection variable. I have a number variable already that I am using to count the number of loops. I don't see a way to convert the number variable to a collection variable, or a way to use the For-Each with a number variable. Help! And thanks in advance!

Labels: (1)
0 Kudos
Reply
4 Replies
nj
Nintex Newbie

Re: How Do I Use For-Each With Regular Number Variable

Jump to solution

Just to clarify, you're looking to use a For Each, and you have a number variable that should increase by 1 every time the For Each loop triggers?

 

You're correct that it uses a collection variable. Here's the documentation on that workflow action: https://help.nintex.com/en-US/nintex2013/help/#Workflow/RootCategory/Actions/Nintex.Workflow.ForEach...

 

You could use your number variable in the Index field of the for each, then run the rest of your operation on the collection. 

 

I feel like this would be easier to explain if we knew what else you were doing as well. If all you're doing is a loop with an increasing number, a For Each isn't exactly the right fit.

 

The name kinda tells what it's for. "For Each" as in For Each of these cars in my collection named collCars, store the result(or the single car we're working on at one time) in varCurrentCar, then do your actions, and it repeats for each car in the collection. Some pictures below to help show that.

 

image.png

 

image.png

0 Kudos
Reply
rogerb
Nintex Newbie

Re: How Do I Use For-Each With Regular Number Variable

Jump to solution

nj,

Here is the complete scenario.

 

I have a record that I want to duplicate, and there is a field for the user to enter how many dupes they want. In the loop I query to find the next available project number from a second list. The duplicated record is then updated with the project number. Then the project number in the project number list is updated as unavailable. Here's some pseudocode for what runs inside the loop if that makes it more clear.

 

Query project number list for next available number

Copy current item

Update copied record with new project number

Update project list to make project number unavailable 

Add project record to block of project numbers variable

 

As I've walked through this I've found several things to move outside the loop. They are items that only need to be done once. That should speed up the workflow some.

 

 

0 Kudos
Reply
emha
Nintex Newbie

Re: How Do I Use For-Each With Regular Number Variable

Jump to solution

have a look on this blog how for-each loop could be used in place of regular loop.

https://community.nintex.com/t5/Community-Blogs/Safe-Looping-or-Not-that-is-the-question/ba-p/82441?...

 

 

but I'd say regular loop is better/safer for your scenario...

sharepoint will batch actions (writes) you perform within the loop. so an update to "make project number unavailable" need not effectivelly be written to sharepoint list when next loop iteration is querying next available number. so it will cause duplicate project identifiers.

it will very likley be random, sometimes it will work, sometimes not.

 

overall approach of this kind of (likely-to-be unique) numbering is not very reliable...

0 Kudos
Reply
rogerb
Nintex Newbie

Re: How Do I Use For-Each With Regular Number Variable

Jump to solution

I changed up the way I run the workflow. I pull a variable (my number variable) number of projects #s into a collection and then run the for each with that. Works brilliant, and thanks for all your help!

0 Kudos
Reply