group by attribute from the local variable
Question

Hi all,

I'd like to group by attributes from the local variable.  For example,  John Doe and Jane Doe can have same phone number in the office. So I'd like to group the phone and put the Jane Doe and John Doe in the EmployeeInfoList from the EmployeeInfo2. I've looked up many solutions but none of them is the answer, since it can use the sql group by. But mine is from local variable.

Attached images are the example that I illustrated.

Thank you.

mvp_badge
MVP

Hi Hailey,

Since the data is not coming from the database, there's no easy way to mimic a "group by". Also, given your example, it seems a "group by" like the database does is not what you want. Because if you do a group by in an aggregate or query, only the grouped by Attributes are available, and any calculated fields using aggregation functions like Max() or Sum().

That said, if it's just the phone number you want to group on, you could easily do that in code. First, use the ListSort to sort on phone number, then loop over the resulting list and compare the phone number with the previous one (that you can store in a local variable). If it's different, you create a new EmpolyeeInfo2 record and add the Employee to its EmployeeInfo list (I'd rename that though, call it EmployeeInfoList or just Employees instead), if it's the same just create a new EmployeeInfo and add that to the current EmployeeInfo2 record.


Hi Hailey Lee

Have you tried to use the List Distinct?


Regards

Gonçalo Almeida

mvp_badge
MVP

I don't think that's what they're asking.

Champion

Hi Hailey,

Can understand do you need to display in the UI the group by attribute from local variable?

In my case, i use tree widget to display and put the local variable list in the source

https://www.outsystems.com/forge/component-overview/31/tree-widget

Hope it helps

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