Flow Designer loop through a column value and create records

davilu
Mega Sage

Our team has a Choice field on a table, with numbers 1-10.  When a user selects a number from that Choice field and submits, we would like to trigger flow designer to create that many records on our case table.  We know that there is a For Each flow logic action, but looks like it wouldn't work with our Choice field.  We realize we can likely script a Business Rule to accomplish this, but wanted to know if this is possible in Flow Designer.

Thanks!

1 ACCEPTED SOLUTION

Jason Nichols
ServiceNow Employee
ServiceNow Employee

Hi davilu,

You could use the Do the following until flow logic. One solution would be to save the value from the choice list as a flow variable, and then decrement the value every time you create a record/case. This would mimic the standard for or while loops in Javascript:

find_real_file.png

The above flow sets a value for the flow variable (I called it Choice in mine). Within the Do the following block I i) create a record and ii) decrement the Choice variable by 1 using a transform function:

find_real_file.png

The block repeats until the value of my Choice variable is 0.

So perhaps a smidgen more than:

var i = 0;
while (i < 5) {
  // do something;
  i++;
}

...but you have your no-code alternative in a flow.

Hope this helps.

View solution in original post

4 REPLIES 4

Jason Nichols
ServiceNow Employee
ServiceNow Employee

Hi davilu,

You could use the Do the following until flow logic. One solution would be to save the value from the choice list as a flow variable, and then decrement the value every time you create a record/case. This would mimic the standard for or while loops in Javascript:

find_real_file.png

The above flow sets a value for the flow variable (I called it Choice in mine). Within the Do the following block I i) create a record and ii) decrement the Choice variable by 1 using a transform function:

find_real_file.png

The block repeats until the value of my Choice variable is 0.

So perhaps a smidgen more than:

var i = 0;
while (i < 5) {
  // do something;
  i++;
}

...but you have your no-code alternative in a flow.

Hope this helps.

Thanks this worked like a charm!

Hi Jason Nichols,

On the first set flow variable what is the value that you are setting? I also have this similar use case.

In a record producer there is  variable number_of_client_ids (choice field), based on this choice looping should done (If the user selects 3 in that choice means looping should be done thrice).

But the problem here is If I am creating a flow variable I have to pass this choice dynamically, but the data pill in flow variable is not accepting the data type choice  find_real_file.png

Hi Krithika,

I was able to set the flow variable from the catalog variable.

In my catalog item, the variable was a Select Box type. In my Set Flow Variables step, I am able to use the catalog variable data pill:

find_real_file.png

When ordering the item, the flow variable value is set to the value from the catalog variable (in the example below, 2😞

find_real_file.png