Hi, normally this type of scenario would be driven by something like a related records table, dependent value, ref qualifier or similar. So potentially you take refField, lookup the custom table for a match, and return the mapped 'choice' value.
Another simple method would be to concatenate you values as a comma separated string (or keep in an array if you like) but use string indexOf() method to see if your refField exists in the string, if true return choiceX and this reduces your code to simple to follow if elseif conditions.

I see no value in searching your arrays using a loop as each array needs to be checked separately and all you are doing is a true\false check which is effectively just a variation on indexOf() and delivers no array specific functionality.

If you use indexOf() you can also maintain the reference 'strings' as system properties, which means any updates are configuration change not code and so may follow a less invasive change management cycle.

 

 

 

View solution in original post