Skip to main content

i have a XML which has an element country and i have to check whether this country is part of my list.

country in (‘USA’,’AUS’)

is there any component where i can configure or i have to write in Evaluator to handle this logic

 

As far as I know, there's no specific string-in-list-of-strings type of function, but our Expression Language should be able to handle this. In particular, your expression can combine checking if the record value matches some string (e.g.,,’USA’) with the logical or operator to chain it with the other values. 


i have gone through the page and i could find only value compared against only value but not value against list of values. if i miss anything please direct me to correct page


Yes, that's what I said. Just chain two value-against-value functions with the logical or. 


i was able to achieve like below in expression evaluator componenet, but is it efficient way or is there any other way 

 

${record:value('/lastName') == 'US'} || ${record:value('/lastName') == 'CA’}


That's the way I'd do it. :)


Hi @ashok verma and @dima 

While I see the above question is resolved, I would like to share a different option with the community as I feel that’s more scalable in nature.

When you have a requirement to compare against a list which has limited elements in it (for example only 2 countries above), then probably the use of expression evaluator is adequate. But you can’t have such hand written conditions written in an expression evaluator if the list is big.

My suggestion is to make use of “Static Lookup” processor. I’m attaching the sample pipeline here. As you may see, the static lookup processor has configurations for 251 country codes with corresponding values set as either 0 or 1. A sample below:

/

  {

    "key": "AUS",

    "value": "1"

  },

  {

    "key": "USA",

    "value": "1"

  },

  {

    "key": "IND",

    "value": "0"

  }

]

 

The lookup conditions just looks up for the input country - searches that in the static store and provides you the result value of 0 or 1.

So based on your requirement, today you can set the value to 1 for USA and AUS and rest all 0. Tomorrow if you need to add few more entries, then just make the values of those countries to 1. Once the lookup matches with the given country, you can use the value (0 or 1) and decide whether it’s matching or not.

Let me know how you find this solution?

Regards

Swayam

CC: @Drew Kreiger 


Reply