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
  • The way I'd approach this is to cycle through the local!myDictionary variable checking for active = "A" and if it does return the color index. See code below.

    There are many ways to achieve a similar outcome though so depending on your exact use case a different approach may be better/more efficient. This is just one way.

    a!localVariables(
      local!myDictionary: {
        {
          item: 1,
          active: "A",
          description: "Widget",
          color: "Green"
        },
        {
          item: 2,
          active: "B",
          description: "another",
          color: "red"
        }
      },
      a!forEach(
        items: local!myDictionary,
        expression: if(
          exact(
            tostring(
              index(
                fv!item,
                "active",
                {}
              )
            ),
            "A"
          ),
          index(
            fv!item,
            "color",
            {}
          ),
          {}
        )
      )
    )

Reply
  • The way I'd approach this is to cycle through the local!myDictionary variable checking for active = "A" and if it does return the color index. See code below.

    There are many ways to achieve a similar outcome though so depending on your exact use case a different approach may be better/more efficient. This is just one way.

    a!localVariables(
      local!myDictionary: {
        {
          item: 1,
          active: "A",
          description: "Widget",
          color: "Green"
        },
        {
          item: 2,
          active: "B",
          description: "another",
          color: "red"
        }
      },
      a!forEach(
        items: local!myDictionary,
        expression: if(
          exact(
            tostring(
              index(
                fv!item,
                "active",
                {}
              )
            ),
            "A"
          ),
          index(
            fv!item,
            "color",
            {}
          ),
          {}
        )
      )
    )

Children