Compare list with string

Hi,
I am trying to achieve the below in reformat:
I have an array/list name pkey which gets the value from Parameter.
string pkey = split(getParamValue(“t_key”),‘;’);
From the above code say t_key contains {Name;Grade} then pkey will contain [Name,Grade].

Now I need to loop for each input record and perform some operation only if the input metadata does not contain pkey value:
Code is something like this -
for(integer i = 0; i < length($in.0); i++) {
if(getFieldLabel($in.0,i) != “Name”) {

}
}

But instead of having the “Name” hard-coded I need to compare the pkey values directly as it can contain more than one value dynamically.
So if I use the below code:
for(integer i = 0; i < length($in.0); i++) {
if(getFieldLabel($in.0,i) != pkey) {

}
}

I get error as “Incompatible types ‘string’ and ‘string’ for binary operator.”
Any ways how I can rectify this code?

Hi,

The error is a result of trying to compare STRING with LIST of STRINGS - for equality - which of course does not work. What you need to do is to check whether the LIST contains your STRING.
For this, the function containsValue() can be used.

Your code could be re-written this way:


for(integer i = 0; i < length($in.0); i++) {
if(! containsValue(pkey, getFieldLabel($in.0,i)) {
<do some operation>
}
}