Skip to main content
amitk0023
Participating Frequently
Aug 8, 2022 10:37 AM UTC
Question

Count the list of array

{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
        Participating Frequently
        Aug 8, 2022 10:48 AM UTC

        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
        Participating Frequently
        Aug 8, 2022 10:48 AM UTC

        yes

        stefanhelzle0001
        Brainy
        Aug 8, 2022 10:56 AM UTC

        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
        Participating Frequently
        Aug 8, 2022 10:57 AM UTC

        Thank you, Stefan for your reply 

        harshitb6843
        Brainy
        Aug 8, 2022 10:57 AM UTC

        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
        Aug 8, 2022 1:32 PM UTC

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

        The Expression Guru
        csteward
        Brainy
        Aug 8, 2022 3:06 PM UTC

        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
        Participating Frequently
        Aug 8, 2022 3:16 PM UTC

        its  give  nested result

        csteward
        Brainy
        Aug 8, 2022 3:32 PM UTC
        its  give  nested result

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

        shukurs0001
        Known Participant
        Sep 9, 2022 9:00 PM UTC

        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
        Participating Frequently
        Jan 13, 2023 7:54 AM UTC

        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
        Brainy
        Jan 13, 2023 4:08 PM UTC

        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]