Skip to main content
amitk0023
August 8, 2022
Question

Count the list of array

  • August 8, 2022
  • 16 replies
  • 1 view

{1,2,3}, {56,76,54,32}, {12,23,45,54,32,54}, {1,2,3,4,5,6,7}, {8,9,10,11,12,13,14,15}

Please suggest how do this using foreach function get output like this, 

  • "length of array 1 is 3"
  • "length of array 2 is 4"
    • "length of array 3 is 6"
      • "length of array 4 is 7"
        • "length of array 5 is 8"

        16 replies

        scarg
        August 8, 2022

        Hi Amit,

        Just to clarify, your input is a list of arrays, and you want to output the length of each item (array) in that list, right?

        amitk0023
        amitk0023Author
        August 8, 2022

        yes

        stefanhelzle0001
        Brainy
        August 8, 2022

        Did you try to use count() inside a foreach()? This seems pretty trivial to do. What did you try, what was the outcome?

        amitk0023
        amitk0023Author
        August 8, 2022

        Thank you, Stefan for your reply 

        harshitb6843
        August 8, 2022

        Appian doesn't really support list of list. It will flatten them down. If you are building this list via some logic, then I would recommend you to count it then and there. 

        mikes0011
        Brainy
        August 8, 2022

        Use a list of dictionary instead, where each dictionary has an array as one of its properties.

        The Expression Guru
        csteward
        August 8, 2022

        As the others mention, if these are properly defined in a dictionary or map, use:

        a!localVariables(
          local!data: {
            a!map(list: {1,2,3}),
            a!map(list: {56,76,54,32}),
            a!map(list: {12,23,45,54,32,54}),
            a!map(list: {1,2,3,4,5,6,7}),
            a!map(list: {8,9,10,11,12,13,14,15})
          },
        
          a!richTextDisplayField(
            value: a!richTextBulletedList(
              items: a!forEach(
                items: local!data,
                expression: a!richTextListItem(
                  text: concat(
                    "length of array ",
                    fv!index,
                    " is ",
                    count(fv!item.list)
                  )
                )
              )
            )
          )
        )

        amitk0023
        amitk0023Author
        August 8, 2022

        its  give  nested result

        csteward
        August 8, 2022
        its  give  nested result

        I'm not sure what this is referring to..

        shukurs0001
        September 9, 2022

        a!forEach(
          items: {
            a!map(
              id:{1,2,3},
            ),
            a!map(
              id:{1,2,3,7,9},
            )
          },
          expression: "Length of the array " & fv!index & " is " & length(fv!item.id)
        )

        medap0001
        January 13, 2023

        a!localVariables(
        local!data: {
        a!map(list: {1,2,3,8,9,9,9,9,9,80,90,70}),
        a!map(list: {56,76,54,32}),
        a!map(list: {12,23,45,54,32,54}),
        a!map(list: {1,2,3,4,5,6,7}),
        a!map(list: {8,9,10,11,12,13,14,15})
        },

        a!richTextDisplayField(
        value: a!richTextBulletedList(
        items: a!forEach(
        items: local!data,
        expression: a!richTextListItem(
        text: concat(
        "length of array ",
        fv!index,
        " is ",
        count(fv!item.list)
        )
        )
        )
        )
        )
        )

        csteward
        January 13, 2023

        a!localVariables(
        local!data: {
        a!map(list: {1,2,3,8,9,9,9,9,9,80,90,70}),
        a!map(list: {56,76,54,32}),
        a!map(list: {12,23,45,54,32,54}),
        a!map(list: {1,2,3,4,5,6,7}),
        a!map(list: {8,9,10,11,12,13,14,15})
        },

        a!richTextDisplayField(
        value: a!richTextBulletedList(
        items: a!forEach(
        items: local!data,
        expression: a!richTextListItem(
        text: concat(
        "length of array ",
        fv!index,
        " is ",
        count(fv!item.list)
        )
        )
        )
        )
        )
        )

        When re-posting solutions from earlier in the thread, please use Insert -> Code [emoticon:4191f5ee34e248a29fa0dbe8d975f74a]