Manage Learn to apply best practices and optimize your operations.

Look for a value in a multi-valued text field

Ever wanted to know if a value is in a list of values using LotusScript? This tip explains how to find out.

View member feedback to this tip.

Ever wanted to know if a value is in a list of values using LotusScript? It is a usual practice to loop from 0 to ubound of a doc field. What if the list is too big? It might need too many iterations before knowing if a value is in a list of values.

Here is a simple Evaluate function that tests to see if "X" is in a list.

IsXin = Evaluate("@IsMember
(" & """" & "X" & """" & "; 

If IsXin(0) = "1" then
  'X found in the list.
End if


The tip does not take into account the possibility that the value you are searching for contains characters that may cause the Evaluate macro to fail. In the example given, the author is looking for the value "X." In practice, the value will not be hard-coded, but will come from a field or variable. What if that value contains quotes? For example, the LotusScript representation would be:

"So, I says to the guy ""You lookin at me?"""
The Evaluate macro will fail because it will expect to have the double quotes escaped with a backslash. In other words, the value will have to be passed in to the evaluate macro as:

"So, I says to the guy \""You lookin at me?\"""
The same applies if the string contains backslashes. One suggestion to handle this is the following:

'Here is the value we are 
looking for
x = "So, I says to the guy "
"You lookin at me?"""
'Save it to a temporary field 
in the document
Set fldTemp = doc.
("TemporaryField", x)
'Check if the value is contained 
in the multi-value field
IsXin = Evaluate("@IsMember
(TemporaryField; MultiValuedFieldName)
'Now remove the temporary item
'(or set it's SaveToDisk property to 
False - then you don't have to delete it)
If you don't want to touch the working document, create a temporary document and do the same Evaluate, but using the temporary document as a context, such as:

x = "So, I says to the guy "
"You lookin at me?"""
Set tempDoc = doc.ParentDatabase.
MultiValuedFieldName doc.
("TemporaryField", x)
IsXin = Evaluate("@IsMember
(TemporaryField; MultiValuedFieldName)"
, tempDoc)
'We do not need to save the document - 
just throw it away
-- Cesar M.

Do you have comments on this tip? Let us know.

Dig Deeper on LotusScript



  • iSeries tutorials's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...