I have a nested loop running in my app, to create rows for options selected in the enum list.
In case of 2 pets & 1 service its works well. But when I select 2 pets 2 services, the appsheet hangs. I dont know why? Please assist. I have attached a video for the same.
https://drive.google.com/file/d/157Ol5_6V91FZ0_-aPSOym2S4UzdblC9y/view?usp=drive_link
When the app hangs while running a loop, it means the condition you've provided to end the loop is not being met. What is your condition for ending the loop?
I agree with @Steve , one of the Behavior conditions is not set properly to stop the looping.
Honestly what I made is exactly from Marc's post. I am still trying to grasp completely what is happening. But if I am right the condition for the loop ending is [service count]>0 and for another action is [pet count]>0
Link to Marc's post which I referred: https://www.googlecloudcommunity.com/gc/Tips-Tricks/Nested-Action-Loops/m-p/377956#M5211
Let's try to move the troubleshooting out of Tips & Tricks and keep it here in Q&A. I'd rather not slog through the other topic to tease out the details. Can you elaborate more here?
@Aditya_K1999 wrote:
But if I am right the condition for the loop ending is [service count]>0 and for another action is [pet count]>0
It also depends on how you are managing the counters. For the expression you listed above, the counters MUST start at the max count and DECREMENT by 1 on each iteration. Additionally, if you have nested loops the inner loop MUST reset back to the max count on each iteration of the outer loop.
For what it's worth...,
I do not think you need nested loops in this use case. As I understand it, you are adding the SAME row types and only need to assign the correct Pet and correct Service based on the selection lists - plus maybe assign some other related details.
You only need nested loops if you are adding or updating DIFFERENT row types.
By handling this in a single loop, it will be more efficient and a LOT fewer actions and a LOT less confusing.
The way I would handle this is to include one additional column named maybe [Add Row Count]. This column is assigned the value [Pet Count] * [Service Count] - total number of rows to be added - and its only purpose is to control the looping.
On each iteration, I would use [Pet Count] and [Service Count] as the index into the selection lists to assign the correct Pet and service.
Additionally, on each iteration, an action would control the updating of the "count" columns, paying special attention to resetting when appropriate. For example, let's say you have 2 Pets and 3 Services and you want to process by Pet - i.e. for the same Pet assign the 3 services first then assign the 3 services for the next Pet.
On each iteration, you keep the Pet Count the same but would decrement the Service Count. When Service Count reaches zero, then decrement Pet Count AND reset the Service Count. Obviously, Add Row Count is always decremented.
I hope this helps! If not this time, at least in the future.
Thank you @WillowMobileSys I kind off understand what you are trying to say.
If you don't mind, this is till new for me & if possible I would like to execute this in a single loop rather than a nested loop. By any chance can you help me with a sample app, it will help me understand the process.
Would really appreciate it.
Thank you!
User | Count |
---|---|
14 | |
11 | |
9 | |
7 | |
4 |