57
Views
3
Comments
Solved
Nested For Each does not Execute

Hi All, 

I'm trying to do a very simple loop to get all the information within a structure in a single line output. 

I would like to loop through the GetRolesResponse and subsequently the EnvironmentPermissions structure which maps to the GetRolesEnvironmentPermission (see green outlined boxes above) into a simple RolesPermissionStructure (see below). 


I have a simple nested foreach loop which loops through the GetRolesResponse List and appends the ListAppendRoles and adds the available information into the RolesPermissionStructure and then loops through the EnvironmentPermission List to add the full set of information. I realise that I will have duplicate rows (if this works) but that is fine for now. 

The issue that I'm having is that the nest foreach loop does not even execute and I only get the information from the first foreach loop. 

As a traditional developer, I know this would be really easy to write out in code but I'm struggling to understand what is happening here after spending so much time on this. 

For anyone who is interested in more information, the roles are basically from LifeTime's API and I'm basically trying to write a simple module to export the information to an excel sheet. 

https://success.outsystems.com/Documentation/11/Reference/OutSystems_APIs/LifeTime_API_v2 

Is there a better way to go about this or am I heading down the wrong path? 

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP
Solution

Hi Darrick,

You say "the nest foreach loop does not even execute" - what do you mean by this, and how have you observed this? Did you debug the code? Did you check how many elements there are in the sub-list? Or did you just assume it doesn't execute because in the output your list is empty (so you assumed the second ListAppend wasn't executed)?

One final note: to make your code easily readible, layout similar code in a similar way. Having the first ListAppend to the right of its For Each, but the second ListAppend to the left is bad coding practice.

UserImage.jpg
vikas sharma
Champion

Hi

As per your problem statement : " would like to loop through the GetRolesResponse and subsequently the EnvironmentPermissions structure which maps to the GetRolesEnvironmentPermission (see green outlined boxes above) into a simple RolesPermissionStructure (see below). "

So your first loop should be on list of GetRolesResponse and in this loop there will be another loop on EnvironmnetPermissions. 

If still facing issue please share OML file for this.

regards

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP
Solution

Hi Darrick,

You say "the nest foreach loop does not even execute" - what do you mean by this, and how have you observed this? Did you debug the code? Did you check how many elements there are in the sub-list? Or did you just assume it doesn't execute because in the output your list is empty (so you assumed the second ListAppend wasn't executed)?

One final note: to make your code easily readible, layout similar code in a similar way. Having the first ListAppend to the right of its For Each, but the second ListAppend to the left is bad coding practice.

UserImage.jpg
Darrick Ho

Hi Vikas and Kilian, 

It turns out that my loop was correct! The issue was that I didn't specify the parameters in the API call hence it was returning nothing. I assumed the parameters in the API test windows would transfer over and did not realise that it had to be specified again. So Kilian was right that I assumed it did not execute cause my list was empty. 

I am not able to debug because I did not create any screens for this application unfortunately. 

Much thanks to the two of you for taking the time to respond!  

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.