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" & """" & "; MultiValuedFieldName)", doc) 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. ReplaceItemValue ("TemporaryField", x) 'Check if the value is contained in the multi-value field IsXin = Evaluate("@IsMember (TemporaryField; MultiValuedFieldName) ",doc) 'Now remove the temporary item doc.RemoveItem("TemporaryField") '(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. CreateDocument tempDoc.ReplaceItemValue MultiValuedFieldName doc. GetItemValue(MultiValuedFieldName) tempDoc.ReplaceItemValue ("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.