Nested Action Loops

I built this functionality today for a client, it seemed very share-worthy, especially since I wasn’t quite sure it would work until after I built it.

There have been many posts about how to setup looping actions and how to automatically generate a number of new records. If you haven’t read those threads, you should start with those before reading this one. I may or may not come back to edit this post to link some of those other threads. Well here is one at least, since the community is trying to tell me my “topic is similar to…” :

This is an even more advanced setup, where there is a loop within a loop.

The functionality is built to allow employees to request certain shifts across certain dates. We wanted the app users to be able to quickly select multiple shifts and multiple dates, so I setup two EnumLists for them to select multiple from, inside a single record.

Column structure for **shift_request_input** Table

For the schedulers to do their job, and be assisted by some app automation, it is much easier/better to see individual records linking each single shift to each single date. So what I wanted to do here is to create all combinations of shifts versus dates from these two EnumLists.

As you can hopefully already tell, we can’t just loop across one EnumList and create the records, we need to have an inner loop to loop across the 2nd EnumList within the loop for the first EnumList.

The general overview strategy here is:

1. Outer loop
  A. Re-calculate COUNT for inner loop
  B. Execute inner loop
    i.Inner loop
      a. Create a new record
      b. Decrement inner loop count
      c. Re-loop inner loop (IF count > 0 )
  C. Decrement outer loop count
  D. Re-loop outer loop (IF count > 0 )

And here is a general overview screenshot of the set of actions:

*Extra bonus tip here too, you get to see the naming schema that I use when creating large grouped action sets.*

Action Set Overview.

And here are the individual Action Definitions.
GROUP 7 | outer group , loop over dates


GROUP 7-1 | reset shift_count


GROUP 7-2 | execute inner group


GROUP 7-2-1 | inner group , loop over shifts


GROUP 7-2-1-1 | create new shift_request

You can see 90% of the expressions there, but they are simply:
INDEX( [enumlist] , [enumlist_count] )

GROUP 7-2-1-2 | decrement shift_count


GROUP 7-2-1-3 | re-loop inner group

GROUP 7-3 | decrement date_count


GROUP 7-4 | re-loop outer group

This entire Action group is set as the Form Saved Behavior for the shift_request_input Form view. I might move it to be executed via Bot so that the users don’t have to potentially sync dozens of records on their end, but I haven’t gotten that far yet.

* [employee_month] is just a Ref column to a parent record. *


This IS absolutely share-worthy

Nice one! Small moonwalker

Only hiccup I see is this:

  • This unfortunately doesn’t work.
    • Bots can’t run through loops - at the moment at least.

There used to be a loop depth limit listed in the limitations documentation, but it’s not listed anymore (probly since bot-loops don’t work at the moment).


What is the end result for the user? I understand the looping, i use it myself, but can’t visualise the purpose, thanks in advance

1 Like

There are 2 different types of users here: “requesters” and “schedulers”

This is the preferred/easiest way for the requesters to enter their shift requests. Here it is just a single record, but it indicates 4 shift requests.


The purpose of the nested loop is to split this single record into 4 separate records, the 4 possible combinations (2 x 2), which is the preferred form for the records to be in to be used by the schedulers. These 4 records would look like this:


A single loop could only handle the case where you’d have one List type column. You need another nested loop for every additional List type column that you want this sort of functionality to act on.


To answer your question from a user experience point of view, one advantage with the looping construct @Marc_Dillon has highlighted, you can provide a quicker way for the users to select a list of items that are normally recorded as child rows. Adding each child row one by one, especially when there are several, is extremely monotonous and slow - i.e. inefficient.

For example, in an Ordering process, you could provide the user with a dropdown list of products that they can select multiple items from (an EnumList column). When they Save, you can use the looping pattern to automatically add the child Order Detail rows to the Order. You can then finish by presenting that list of Order Detail rows in an editable table where the user can simply go down the table rows and adjust the Quantities (as well as other details) of each ordered product in a single view.

Another example might be assigning a list of programs or services to a client. Instead of adding one-by-one use the EnumList approach above.

There are many other use cases for this looping construct but the main idea in all of them is to give the user a quick and easy way to select the items they want/need and let the system do the majority of the work.


Wow! I have looked for something like that for a while, i built a routing app and needed all possible combinations of locations, ended up doing it with excel. This may be the solution.