Looping over several rows

I am wondering if we can loop over tasks using START and END for lists and Enumlists.

I need to add rows to another table using rows from this table and this table has Enumlist columns over which I need to loop.

This may be a different question but how about nested loops involving children and grandchildren?

3 29 2,969
29 REPLIES 29

Itโ€™s painful but doable to handle LISTS and ENUMLISTS.
Have to keep adding Branch if Condition steps for as many as required until max length of LIST.

Please consider a way to specify a step which is essentially a loop over the LIST or ENUMLIST.

Former Community Member
Not applicable

We do plan to add support for looping over a set of rows inside a process in the future.

Currently you can process a set of rows using the for each attribute in โ€œScheduledโ€ events. In this case the process that is selected in the bot will execute N times, where N = the number of rows in the selected table.

@prithpal A scheduled event does not work for my user case, where as part of a governance function someone is setting controls based on products that match a specific search criteria. Therefore for each matching product I have to create a new Control in the intermediary table Product_Has_Control. Hence the loop element.

I have previously implemented the loop using actions as per the comment from @MultiTech_Visions, which works. However I was hoping to use the new Automation feature as it is a little easier to comprehend whatโ€™s going on and possibly maintain going forward.

Is using Automation for loops now viable?

Hi @prithpal as mentioned in my previous post, using the scheduler-event as outlined above just does not work for my use case. Dishearten to see the ability to create new Workflows has been disabled; I assume in readiness to switch-over to Bots.

However since the Automation I have seen does NOT support loops, why has the ability to create new workflows been disabled?

See screen-shot below of the disabled new Workflow rule

Former Community Member
Not applicable

Automation is a superset of workflow rules. Whatever works in workflow rules is supported in Automation.

Loops โ€œareโ€ supported in Automation just as they were in workflow rules via the โ€œForEachโ€ option in the Scheduled Event.

What we were discussing earlier in the thread it that we are considering supporting loops โ€œinsideโ€ a process โ†’ this was never available within workflow rules to begin with.

Hi @prithpal do you have an eta on loops inside a process via Automation? Iโ€™ve implemented every version of loops using various workarounds posted by members of the community and they are surely less efficient than an official implementation would be.

We are also using webhooks but they have their own problems requiring the app to be online and execute a sync before the changes show up on the client. A loop/ForEach action that could be executed offline like other data change actions that would be the ultimate feature.

Having a proper loop/ForEach feature as an action, that could also be called by a process is my number one ask. It is the main thing that would make our lives easier and make Automation a joy to use. It would also clean up the huge amount of workaround actions and/or workflows that many of us currently have.

**Edited for clarity and to specify loop/ForEach action that can be used offline and instantly client-side.

This true too for any solution that uses Automation.

Youโ€™re right. I guess the more specific request would be to have a loop/ForEach function available as an action.

Just so I understand:

โ†’ this was never available within workflow rules to begin with.

So a workflow could not call an Action that executed a series of steps Correct?

That is what I was going to attempt before the Workflow got disabled in favour of Bots.

Just to add here is a screen-shot of the โ€˜newโ€™ Bot.

The Repeat Member add does the following:

  1. Repeat member add task

    • calls โ†’ Loop (repeater) Action | Create ProductGroup Member
  2. Loop (repeater) Action | Create ProductGroup Member

    • calls โ†’ Loop Action | Create ProductGroup Member
  3. Loop Action | Create ProductGroup Member

    1. calls โ†’ Action | New 1st group member then
    2. calls โ†’ Loop (repeater) Action | Create ProductGroup Member (step 2)

@prithpal Would like to know if it is possible to trigger recursive actions from within a Bot?

Steps 2, 3.1 and 3.2 check there are remaining_members left to process.

Would welcome your thoughts.

No news regarding calling a recursive action within a Bot. I also have a call out with the development team. Any ideas? @prithpal

Wendy would you be able to describe what you mean by recursive actions ?

In workflows and bots DataChange actions invoked by Workflow rules do not trigger other workflow rules or bots.

Hi @Dan_Bahir apologies for the delay, was an AL.

A good example is given above in the screen-shot. In this instance products that belong to a group have to meet a specific criteria. Once identified, a record is created in an intermediary table called: ProductGroup_Has_Member

These records need creating to maintain the many-to-many relationship between ProductGroup has many products and a Product can belong to many ProductGroups.

The trigger is saving the details of a ProductGroup which may have amended the criteria. Hence the start condition: Check | Product group members to add

In the detailed outline of this discussion is mentioned looping over a list of โ€˜somethingโ€™ until that list has been processed. Since there is no LOOP construct in AppSheet, we have to make-do with Actions calling each other. The recursive actions are outlined again below:

  • Loop Action | Create Product Group Member calls โ†’
    Add | First Product Group Member
    Loop (repeater) Action | Create ProductGroup Member*

The action: Loop (repeater) Action | Create ProductGroup Member calls โ†’ Loop Action | Create Product Group Member hence creating the recursive loop.

But, as explained earlier, doing this on the client-side is too slow as it temporarily freezes the SAVE action, meaning the user has to wait for some of the processing to have been completed, before the using the app further.

Hence the question asked here: about placing this in a Bot, so it can be used server-side. Having tried most of the solutions outlined, still not found one that works without issues for maintaining a many-to-many relationship. Never got an answer from AppSheet as to what is the recommended approach for dealing with many-to-many relationships. I am sure there are lots of AppSheet community members who would like an answer to that question.

If you already have a set of Actions executing the desire loop you want, you should be able to trigger a Data Change process that executes the same Action loop. That would force those actions to run on the server side within the scope of the process.

Mr Jay, you can do that with Webhook as you are able to use Start expression.

I donโ€™t want a webhook!!

So Iโ€™ve got a system inside an app Iโ€™m working that does exactly what youโ€™re asking for @Bellave_Jayaram - but with actions.

  • From a Parent level, we create child records, then associated grandchild records (with the grandchildren being related to both the parent AND the appropriate newly-created child).

I spent some time this morning trying to figure out how I could port this process over to the automation sideโ€ฆ and I think I got it figure out - but I only got as far as looping through the list and creating the child records and ran into a bug due to a cycle.

If we could get processes to accept cycles - as long as the first step in that process is a condition - we could โ€œeasilyโ€ implement a system that would allow us to loop over lists.

  • And since processes allow us to essentially โ€œpushโ€ data into other tables, it would solve something thatโ€™s been desperately missing from the platform FOREVER.
    @prithpal

Thisโ€ฆ might be a long video - just fyi. (^_^)

Hey!
I join this task.
Before automation I had to solve a similar problem with external tools and I thought that automation would do such things by default โ€œin a boxโ€.
In general, such scenarios are one of the most efficient for large amounts of data with a large number of intermediate calculations.
What restrictions can there be or are there now on looped scenarios?
The other day I wanted to solve my problems on the basis of automation.

@prithpal as you can see in the below examples an astronomical amount of work has gone into working around the lack of a loop/ForEach action. A proper new action would also lower the barrier for entry in Appsheet. It took me a long time to understand these posts well enough to implement critical features in our apps.

And my every single app have lopping action that works with workflow. Sadly It is very unfortunate right now for someone who is working with developing applications for manufacturing companies.

Sometimes I have 5 rows to 15 rows to be added to another sheet using looping action. When a 3 row is added on an average its 30 rows. If itโ€™s an action it takes atleast 1-2 minutes to complete the sync. The users use the app and they update everything faster. If they update or add like 3 orders that contains 3 products it would be approx. 90+ rows each time to be looped. That is not at all feasible if I use Looping action. Disappointed with the current update !

I agree totally with with the comments from @APiCC_Conor and @Rifadm817. AppSheet is a great platform to work with, but appears to be missing an important construct enabling Loop capability both instantly on the client-side and in the background, server-side.

I have tried 3 of the suggested work-arounds, with limited success. For my use-case: to use the Scheduled Event it would have to poll for updates every few minutes, 24/7, which cannot be an efficient approach.

Now attempting a 4th solution iteration removing dereferences for Select statements as suggested by @Steve in an attempt to speed-up the โ€˜loopโ€™ updates.

Hi Wendy,

We currently do not have a good solution for this use case. In our road map we are planning to introduce a for each step that would allow to provide an expression that would return a list of rows which then you could execute a series of steps or a sub process on.

In the mean time we will expose the โ€œExecute an action on a set of rowsโ€ and โ€œExecute a sequence of actionsโ€ actions that in combination might allow you to implement the looping you want.

Just wanted to add that I have the same issue here.

Iโ€™m fairly new to Appsheet (just a few months use) and while I was initially impressed with what could be achieved in a short amount of time, I now keep running into roadblocks caused by the lack of very basic functionality, particularly in Appsheet Automation.

I can understand Appsheet wanting to keep things as low-code/no-code as possible, but this shouldnโ€™t mean ditching basic functions such as iteration (โ€œforโ€ and โ€œwhileโ€ loop equivalents).

EDITED: Moved my list of issues to a new topic here since most of them werenโ€™t related to looping

I am new to AppSheet and am struggling to automate the creation of tasks for a related request upon request submission. Please see the attached flowchart for the desired behavior. I thought this would be an easy ask, however, upon Googling examples of Event triggered loops in AppSheet I was distraught to find this community post about how this functionality appears to be completely lacking.

Can someone assist me with a workaround, please?

Sure! First, a caution, this past week an issue surfaced (I think a bug) where iterative actions from a Bot only processed the first row. The same action set, activated on Form Save behavior, processed all rows as expected. So, I would advise to begin implementing the below on the Form Save behavior when entering a new Request. This will avoid any potential bug while creating the process and there is no lost effort this way.


Here is the looping construct I would create. It takes advantage of a recursive call ability to repeat adding Task rows WHILE there are still Categories that have NOT been added to a Task. The Steps are:

1) Create a looping control action. It basically starts off the recursion but has the check as to WHEN to stop looping. It looks like the below image - wait to add the Reference Action. Thatโ€™ll be done in a later step

The critical part is the Behavior criteria that allows the action to run and stop. I used this expression:

COUNT(SELECT(Categories[Category ID], NOT(IN([Category ID], Select(Tasks[Category], [Request] = [_THISROW].[Request ID]))))) > 0

2) Create the action that adds the Task Rows. See below.

To assign the Categories, the action simply picks off the first one in the list of Categories that have NOT yet been assigned to a task for this Request. No Behavior criteria on this one.

ANY(SELECT(Categories[Category ID], NOT(IN([Category ID], Select(Tasks[Category], [Request] = [_THISROW].[Request ID])))))

3) Create a Grouped Action that calls the action to add the Task Row and then calls the โ€œtopโ€ action to loop again. It looks like the below and no Behavior criteria.

4) Add the Grouped action from 3) to the action in 1) as the Reference Action.

5) Attach the action in 1) to the Form Save behavior and Test!


Here is an example run

Categories are:

No Requests or Tasks:

Add a Request. Immediately switching to the Tasks view shows all rows there while updates are still being made to the server. See image.


If your use case requires the use of a Bot, simply add the โ€œloop controlโ€ action to the Process Step and you are good to go!!

I hope this helps!!

Good news!! I created a Bot and attached the above action set and all the expected rows were created. Either the issue I mentioned is only for certain use cases or it has been fixed.

Thank you so very much for taking the time to mock this up and create a tutorial for me! This worked brilliantly and did exactly what I wanted! I am floored by your speedy yet thorough high quality response. I learned a lot from studying all of the steps you provided. Your instructions were very easy to follow with your screenshots and code boxes.

Is there a way to loop through a list and fire workflows? For example, letโ€™s say I have clientโ€™s A, B, and C. Every week I want to send them an email with a list of their outstanding bills. Currently I have a different email template for each client, however, itโ€™d be a lot easier to have one template that I can use for all clients. Does anyone know if this is possible?

Yes, it is. In templates we can insert IF/END blocks so you can conditionally control the appearance of sections in the template based on criteria such as [Customer] = "XYZ".

Putting everything in a single template can cause the template to be overwhelming to maintain if it gets overly complicated.

One way to combat this is to find template info that can be pushed into the customer table as variable data. This is normally some static text that is customized for each client and when in a dedicated template can just stay in the template.

BUT, once you centralize the templates, you find a number of different custom info, messages, etc per client. Place these into the customer table as template customization variables. Then in your template you donโ€™t need a long list of `IF/ENDโ€™ blocks, you just simply show the table column info as a template variable. Some of the customer data may simply be blank and thatโ€™s okay.

This is great. Thanks for your response!

Top Labels in this Space