Hi!
I'm having trouble trying to modify this list of maps (which I get from a!queryRecordType with an aggregation).
local!Grades: {a!map(Group: "A", Excellent: 0, Good: 0, Regular: 0),a!map(Group: "A", Excellent: 2, Good: 0, Regular: 0),a!map(Group: "B", Excellent: 0, Good: 0, Regular: 2),a!map(Group: "B", Excellent: 0, Good: 2, Regular: 0),a!map(Group: "C", Excellent: 0, Good: 2, Regular: 0),},
The aggregation does not allow me to get each Group in only 1 row, because I need to "count" the grades by category (Excellent, Good, Regular)
I would like to display that result in a read-only grid and am trying to prepare the data before displaying it there (as I read in some other suggestions).
The result I am trying to obtain is this:
local!Grades: {a!map(Group: "A", Excellent: 2, Good: 0, Regular: 0),a!map(Group: "B", Excellent: 0, Good: 2, Regular: 2),a!map(Group: "C", Excellent: 0, Good: 2, Regular: 0),},
In other words, I want to match each row of the grid to each group, and the columns will be: "Excellent", "Good", "Regular".
I tried using 2 nested foreach... but it doesn't work.
Please, help me with some ideas!
Thank you in advance!
Discussion posts and replies are publicly visible
It doesn't even really require a nested ForEach or (if you'd rather avoid the legacy function) reduce(), just a bit of reassembly using a!forEach().
a!localVariables( local!Grades: { a!map(Group: "A", Excellent: 0, Good: 0, Regular: 0), a!map(Group: "A", Excellent: 2, Good: 0, Regular: 0), a!map(Group: "B", Excellent: 0, Good: 0, Regular: 2), a!map(Group: "B", Excellent: 0, Good: 2, Regular: 0), a!map(Group: "C", Excellent: 0, Good: 2, Regular: 0), }, local!uniqueGroups: rule!RULE_General_distinct( /* simple helper rule that unions an array against itself */ value: local!Grades.Group ), a!forEach( local!uniqueGroups, a!localVariables( local!listForCurrentGroup: index( local!Grades, wherecontains(fv!item, local!Grades.Group), {} ), a!map( Group: fv!item, ExcellentSum: sum(local!listForCurrentGroup.Excellent), GoodSum: sum(local!listForCurrentGroup.Good), RegularSum: sum(local!listForCurrentGroup.Regular) ) ) ) )