ListAppendAll only appends one level
Question
Application Type
Reactive

Hi OutSystems friends,

I have a data actions that returns a hierarchy list with categories, groups and subgroups (see screenshot below).

I have made a local variable with a likewise structure (difference is that in the original structure a Id is returned and in the local variable a Link is introduced. Also the local variable concists of two levels instead of three levels). Based on a input parameter the categories with groups or the groups with subgroups should be loaded.

Category/Group example

Appliances
-- Hobs
-- Hoods

Group/Subgroup example
Hobs
-- Induction cookers
-- Gas hobs
-- Ceramic hobs

Since the structure is mostly the same I was thinking of using a ListAppendAll to create the levels I need in my screen. I tried a few things but the list is not being filled as I want to. Only the first child of the parent is being appended to the list. I am not sure on how to solve this and I also do not knowif it is even possible to do what I want to do with a ListAppendAll?

 Unfortunately I am not able to share the .oml but I hope the screenshots help in clarifying my problem.

Thanks,

Bart

Solution

If you say you have at least 2 to 3 levels, you need to for each/loop to the parent, then to the child inside of the parent and to the sub child inside of the child.

As you can see you are just putting the date on the first element.

Regards,

Márcio

Hi Marcio,

Thanks for your reply!

The looping is already happening in the server action that is used in the Data Action. I was hoping that I did not have to do it again but I understand what you are saying and that is exactly the problem I am having right now, so I guess I have to loop in the client action again to get what I want. Is my thinking correct or is there another solution?

If you have the same structure as the output from the server action you don't need to do everything all over again. You just need to use the list append all or the assign and everything will match.

Make sure you are using the same structure! :)

At least that's what I think :D

Hi Marcio,

That is exactly the problem. It's a likewise structure but not 100% the same as you can see in the screenshot below. The structure coming from the Data Action is the original one and is filled with the levels I need. The only thing is that on my screen I only need two out of three levels (based on a input parameter only categories with groups or groups with subgroups are being shown). As you can also see in the screenshot is that the original structure has a Id in the corresponding level and in the new structure this has been replace with a link. You think I can still use a ListAppendAll for this or I need to loop again?

mvp_badge
MVP
Solution

Hi,
Sadly it's a thing in Outsystems. nested lists need most of the time be looped through with a for-loop and listappend etc. (and you have to take care of listclears as well)

Sometime you are in luck and can be assigned as is, but you still have to remember it's a reference ;)

Trying to find the idea but cannot find it.

Hi @J. 

Thanks for your reply. I was also looking into the issue together with @Márcio Carvalho and we came to the same conclusion that it seems not to be possible. Sometimes it is good to know that something you think could be easily done is not possibile. I will stuck to looping for now.

Hi all,

depending on how much you dislike looking at / writing loops, and how often you need to do this, it might be worthwhile to invest in creating mapper actions between 2 list types.  Make it a function and you can use it inside the append all.

If you are working with very large lists, it might be interesting to do a test to check performance of this compared to looping before going this way.

See attached oml.  It is only going 1 level deep, but inside there, you can go an extra level by another mapper if you need.

Dorine

QDR_AppendAllWithLevels.oml

@Bart Nooijens This is what I tried to do(but failed to demonstrate :D), I think you should also try this approach by @Dorine Boudry!

Nicely Done @Dorine Boudry, thanks for showing this solution! :)

Regards,

Márcio

@Márcio Carvalho ah yes! For now I have a working solution with loops and unfortunately I do not have more time to test the solution from Dorine for now. I have downloaded the example of Dorine and will check it when more time is available!

@Dorine Boudry thanks for showing this solution. 

Solution

If you say you have at least 2 to 3 levels, you need to for each/loop to the parent, then to the child inside of the parent and to the sub child inside of the child.

As you can see you are just putting the date on the first element.

Regards,

Márcio

Hi Marcio,

Thanks for your reply!

The looping is already happening in the server action that is used in the Data Action. I was hoping that I did not have to do it again but I understand what you are saying and that is exactly the problem I am having right now, so I guess I have to loop in the client action again to get what I want. Is my thinking correct or is there another solution?

If you have the same structure as the output from the server action you don't need to do everything all over again. You just need to use the list append all or the assign and everything will match.

Make sure you are using the same structure! :)

At least that's what I think :D

Hi Marcio,

That is exactly the problem. It's a likewise structure but not 100% the same as you can see in the screenshot below. The structure coming from the Data Action is the original one and is filled with the levels I need. The only thing is that on my screen I only need two out of three levels (based on a input parameter only categories with groups or groups with subgroups are being shown). As you can also see in the screenshot is that the original structure has a Id in the corresponding level and in the new structure this has been replace with a link. You think I can still use a ListAppendAll for this or I need to loop again?

mvp_badge
MVP
Solution

Hi,
Sadly it's a thing in Outsystems. nested lists need most of the time be looped through with a for-loop and listappend etc. (and you have to take care of listclears as well)

Sometime you are in luck and can be assigned as is, but you still have to remember it's a reference ;)

Trying to find the idea but cannot find it.

Hi @J. 

Thanks for your reply. I was also looking into the issue together with @Márcio Carvalho and we came to the same conclusion that it seems not to be possible. Sometimes it is good to know that something you think could be easily done is not possibile. I will stuck to looping for now.

Hi all,

depending on how much you dislike looking at / writing loops, and how often you need to do this, it might be worthwhile to invest in creating mapper actions between 2 list types.  Make it a function and you can use it inside the append all.

If you are working with very large lists, it might be interesting to do a test to check performance of this compared to looping before going this way.

See attached oml.  It is only going 1 level deep, but inside there, you can go an extra level by another mapper if you need.

Dorine

QDR_AppendAllWithLevels.oml

@Bart Nooijens This is what I tried to do(but failed to demonstrate :D), I think you should also try this approach by @Dorine Boudry!

Nicely Done @Dorine Boudry, thanks for showing this solution! :)

Regards,

Márcio

@Márcio Carvalho ah yes! For now I have a working solution with loops and unfortunately I do not have more time to test the solution from Dorine for now. I have downloaded the example of Dorine and will check it when more time is available!

@Dorine Boudry thanks for showing this solution. 

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