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.
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.
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-3 | decrement date_count
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.