Match Index Result for String

Hello,

I have a similar question to: https://community.appian.com/discussions/f/rules/21530/getting-one-property-value-from-dictionary-based-upon-another-property-value.

But instead of returning true/false, I need it to match it against a string value on match condition:

a!localVariables(
  local!myDictionary: {
    {
      item: 1,
      active: "A",
      description: "Widget",
      color: "Green"},
      {
        item: 2,
        active:"B",
        description: "another",
        color: "red"}
  },
  local!tempResults: if(fn!index(local!myDictionary,"active","") = "A" ,"yes","no"),
  reject(fn!isnull, local!tempResults)
)

The index returns the "A", but when I do a condition against it (if statement), nothing returns. I want the string "Green" returned if it matches "A". IT says it doesn't match it.

  Discussion posts and replies are publicly visible

Parents
  • Hi there,

    This can be effectively achieved using displayValue function(). Try the below piece of code. 

    a!localVariables(
      local!myDictionary: {
        {
          item: 1,
          active: "A",
          description: "Widget",
          color: "Green"},
          {
            item: 2,
            active:"B",
            description: "another",
            color: "red"}
      },
      displayvalue(
        "A",
        local!myDictionary.active,
        local!myDictionary.color,
        ""
      )
    )

  • I really like that! I've never used displayvalue() but it's clearly helpful.

    It does appear to only work for the first match though so I've come up with the following. Is there a better way if the use case requires more than one match?

    a!localVariables(
      local!myDictionary: {
        {
          item: 1,
          active: "A",
          description: "Widget",
          color: "Green"
        },
        {
          item: 2,
          active: "B",
          description: "Another",
          color: "red"
        },
        {
          item: 3,
          active: "A",
          description: "Blah",
          color: "Blue"
        }
      },
      reject(
        fn!isnull,
        a!forEach(
          items: local!myDictionary,
          expression: displayvalue(
            "A",
            {fv!item.active},
            fv!item.color,
            null
          )
        )
      )
    )

  • +1
    Certified Lead Developer
    in reply to ajhick

    While people seem to love solving any challenge using a!foreach, most of the time this is not necessary.

    a!localVariables(
      local!myDictionary: {
        {
          item: 1,
          active: "A",
          description: "Widget",
          color: "Green"
        },
        {
          item: 2,
          active: "B",
          description: "Another",
          color: "red"
        },
        {
          item: 3,
          active: "A",
          description: "Blah",
          color: "Blue"
        }
      },
      index(
        local!myDictionary.color,
        wherecontains("A", touniformstring(local!myDictionary.active)),
        {}
      )
    )

Reply
  • +1
    Certified Lead Developer
    in reply to ajhick

    While people seem to love solving any challenge using a!foreach, most of the time this is not necessary.

    a!localVariables(
      local!myDictionary: {
        {
          item: 1,
          active: "A",
          description: "Widget",
          color: "Green"
        },
        {
          item: 2,
          active: "B",
          description: "Another",
          color: "red"
        },
        {
          item: 3,
          active: "A",
          description: "Blah",
          color: "Blue"
        }
      },
      index(
        local!myDictionary.color,
        wherecontains("A", touniformstring(local!myDictionary.active)),
        {}
      )
    )

Children