32
Views
7
Comments
Reset Start index of For Each loop

Hi All,

I was wondering if there is a way to reset the current rownumber / start index of a for each loop.

The reason I ask is this: 

I have to build a planning tool for some departments that need to answer some forms. Each client is able to select a start date. Starting at this date there are expected due dates per form (which are created by adding days to the start date, admin can enter these per form). Apart from this I have a planning per department which is already known for the entire year. I want to loop my forms and see if the proposed starting date causes any issues with the planning. If so, the logic should automatically set the start date to next week and begin the loop again to see if it matches for all forms this time. 

I have build most of it and it seems to work apart from setting the loop back to index 0 if the planning is full. 

All ideas are welcome! 

Regards, 
Max

mvp_badge
MVP
Rank: #2

Hi Max,

This is not possible using a For Each. If you need that functionality, you'll have to keep an index yourself, and directly index the list.

That said, I somehow think you might overcomplicate things a bit, and an easier solution might be possible.

Rank: #9079

Hi Killian,
Thanks for your reply. I was already expecting this...

Would you have any suggestions on how to accomplish such logic? I am leaning towards a SQL statement with a WHILE loop or something but am not sure about this approach.

Regards,

Max

Hi Max,

Good afternoon!

May I kindly ask what is the Entity design/structure of the Forms/Planning per department you've mentioned? I think a well designed entities may simplify a bit your concern. It's like, applying the right combination of Loop and checking dates via Aggregate filtering that will not affect performance of the app may simplify it.

Thank you and kind regards,

Chris

Rank: #9079

Hi Chris,

My Forms entity consists of basic information needed to create the form. The usefull atributes for this are the permissions (so which department fills this questionnaire), the Hours Needed to fill it, the DaysAllowed (the max amount of days a department has to complete the form). 

The planning entity consist of a WeekNumber, HoursAvailable, HoursNeeded and the departmentId to distinguish the various departments per week. 








Rank: #245

Not exactly sure which solution fits your demand best, but you can use listfilter to get a subselection of your mainlist. Or you can create a server action that returns your exact list and use this while your planning is not full.


Hi Max,

May I kindly ask, why does the Planning entity has HoursNeeded?

Kind regards,

Chris

Champion
Rank: #269

Hi Max,


You could use IF,but carefull with infinite loop.