Skip to main content
Known Participant
Dec 1, 2022 5:56 AM UTC
Solved

Check if all items in array are matched

Do you have any idea on how to check if all values in array matched in appian?

example

arrayValue = {true,true,true}

returns "All Elements are Same"

else returns "Not the same"

stefanhelzle0001
Brainy
Dec 1, 2022 7:41 AM UTC

a!localVariables(
  local!arrayval: {true, true, 1, "hello"},
  if(
    count(union(local!arrayval, local!arrayval)) = 1,
    "All Values are same",
    "All values Not Same"
  )
)

5 replies

rahata9316
Inspiring
Dec 1, 2022 6:46 AM UTC

a!localVariables(
  local!arrayval: {true,true,false},
  local!actuallength: length(local!arrayval),
  local!matchedlength: length(wherecontains(local!arrayval[1],local!arrayval)),
  if(local!matchedlength =local!actuallength ,"All Values are same","All values Not Same" )
  /*contains(local!arrayval,true)*/
  /*if(contains(local!arrayval,true),"Matched","Not Mached")*/
)

stefanhelzle0001
Brainy
Dec 1, 2022 7:41 AM UTC

a!localVariables(
  local!arrayval: {true, true, 1, "hello"},
  if(
    count(union(local!arrayval, local!arrayval)) = 1,
    "All Values are same",
    "All values Not Same"
  )
)

srenj0001
Participating Frequently
Mar 16, 2023 10:03 AM UTC

Yes, that is my recommendation too :-)

Since this way of using "union" is so common - and unintuitive, I have wrapped it into a function removeDuplicates:

Known Participant
Dec 1, 2022 9:31 AM UTC

Thank You Very much <3

alexandru.boerescu
Employee
Dec 1, 2022 11:39 AM UTC

Another option using difference:

a!localVariables(
  local!arrayval: {true, true, 1, "hello"},
  if(
    length(difference(local!arrayval,local!arrayval))=0,
    "All values are the same",
    "All values are not the same"
  )
)