working with List of Maps

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

Parents
  • 0
    Certified Lead Developer

    You could use the reduce() function to iterate on the input data and create a output map. Some ideas here: https://appian.rocks/2022/08/29/complex-algorithms-in-appian/

    Below some example code that picks unique random values from a list. This pattern allows you to put all the code into a single expression. This code does not implement a solution to your use case!

    if(
      ri!isRecursion,
      a!localVariables(
        local!index: ceiling(rand() * count(ri!data.chars)),
        a!map(
          chars: remove(ri!data.chars, local!index),
          output: append(ri!data.output, ri!data.chars[local!index])
        )
      ),
      reduce(
        rule!SSH_RandomPicker(
          isRecursion: true,
          data:_,
          num:_
        ),
        a!map(
          chars: char(65 + enumerate(26)),
          output: {}
        ),
        enumerate(10)
      )
    )

Reply
  • 0
    Certified Lead Developer

    You could use the reduce() function to iterate on the input data and create a output map. Some ideas here: https://appian.rocks/2022/08/29/complex-algorithms-in-appian/

    Below some example code that picks unique random values from a list. This pattern allows you to put all the code into a single expression. This code does not implement a solution to your use case!

    if(
      ri!isRecursion,
      a!localVariables(
        local!index: ceiling(rand() * count(ri!data.chars)),
        a!map(
          chars: remove(ri!data.chars, local!index),
          output: append(ri!data.output, ri!data.chars[local!index])
        )
      ),
      reduce(
        rule!SSH_RandomPicker(
          isRecursion: true,
          data:_,
          num:_
        ),
        a!map(
          chars: char(65 + enumerate(26)),
          output: {}
        ),
        enumerate(10)
      )
    )

Children