Combine the value from two structures

I have one structure with several atributes coming from an Advanced and I am inserting the values on it using one foreach to do it, then I have another structure receiving values from an Aggregate, in the end I need to combine both structures in only one to export the data, how can I combine the values from two diferent structures in only one, knowing that the foreach only make one interaction in one list?

Hi Mário. You can have nested for each loops, the first one iterating the list from the Advanced Query, and the nested one iterating the list from the Aggregate. Then it's just a matter of manipulating the Current of both lists.

However, it's very difficult to know how you want to combine both lists. Is it a cross product? Or join them using a join condition? Or do you want to intersect the lists? These can all be accomplished with the nested for eaches, but the logic is slightly different depending on what do you want to do.

leonardo.fernandes wrote:

Hi Mário. You can have nested for each loops, the first one iterating the list from the Advanced Query, and the nested one iterating the list from the Aggregate. Then it's just a matter of manipulating the Current of both lists.

However, it's very difficult to know how you want to combine both lists. Is it a cross product? Or join them using a join condition? Or do you want to intersect the lists? These can all be accomplished with the nested for eaches, but the logic is slightly different depending on what do you want to do.


Can you show one picture of how it would look like???

Can you give me more details of how do you want to combine the two lists?

Hi Leo,

If both your SQL query and your Aggregate return records that should be merged together... why not do all the work in one single SQL query? (I'm assuming there's a reason for using the SQL query and not an Aggregate)

Hello in case you are not able to get both structures in a single query,


You can create a variable of list record tipe with the structure you want and then do a list append all to both agregate or advance queries to that structure.


If there is the possibility of have duplciated values you can use list distinct after. Both list distinct and list append all are outsystems in build functions.