extract unique values from list of strings

Certified Associate Developer

Hello, I have the following list of strings coming from a query: 

List of Text String - 4 items
"user1"(Text)
"user2"(Text)
"user2; user3"(Text)
"user4"(Text)

How  I can sort that so the final result will be list of strings of only unique values: 


Result:
"user1"(Text)
"user2"(Text)
"user3"(Text)
"user4"(Text)

  Discussion posts and replies are publicly visible

Parents
  • It looks like it's possible that there can be multiple values within a single text item - is that correct? Do you anticipate that it will always show with a semicolon separator if there are multiple values?

    If you are confident in the format, you should be able to do this with several steps: (1) split each item by the semicolon (2) combine them all into a single list and (3) use the union() function to return a unique list of items. Something like this should work:

    a!localVariables(
      local!data: {
        "user1",
        "user2",
        "user2; user3",
        "user4"
      },
      union(
        a!flatten(
          a!forEach(
            items: local!data,
            expression: trim(split(fv!item, ";"))
          )
        ),
        touniformstring({})
      )
    )

Reply
  • It looks like it's possible that there can be multiple values within a single text item - is that correct? Do you anticipate that it will always show with a semicolon separator if there are multiple values?

    If you are confident in the format, you should be able to do this with several steps: (1) split each item by the semicolon (2) combine them all into a single list and (3) use the union() function to return a unique list of items. Something like this should work:

    a!localVariables(
      local!data: {
        "user1",
        "user2",
        "user2; user3",
        "user4"
      },
      union(
        a!flatten(
          a!forEach(
            items: local!data,
            expression: trim(split(fv!item, ";"))
          )
        ),
        touniformstring({})
      )
    )

Children