Home > Domino Tips > Developer > LotusScript > Look for a value in a multi-valued text field
Domino Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

LOTUSSCRIPT

Look for a value in a multi-valued text field


Madan Mohan
07.29.2003
Rating: -1.75- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


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.

Code

IsXin = Evaluate("@IsMember
(" & """" & "X" & """" & "; 
MultiValuedFieldName)",
doc)

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

MEMBER FEEDBACK TO THIS TIP

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.


Rate this Tip
To rate tips, you must be a member of SearchDomino.com.
Register now to start rating these tips. Log in if you are already a member.


Submit a Tip




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
LotusScript
LotusScript finds the first occurrence of a string from the right
Clear Recent Contacts view and prevent repopulation in Lotus Notes 8.x
Search Microsoft Active Directory with LotusScript
Three steps to trap and handle save conflicts with LotusScript
Troubleshoot agents by displaying LotusScript variables online
LotusScript sorts lists alphabetically
LotusScript code rebuilds corrupted busytime.nsf file
Soft-code item names to facilitate LotusScript management
LotusScript agent automates selective mail file replication
LotusScript filters and attaches files to a Notes form

LotusScript
LotusScript finds the first occurrence of a string from the right
Clear Recent Contacts view and prevent repopulation in Lotus Notes 8.x
Search Microsoft Active Directory with LotusScript
Three steps to trap and handle save conflicts with LotusScript
Troubleshoot agents by displaying LotusScript variables online
LotusScript sorts lists alphabetically
Run or restart Notes/Domino agents via text messages
LotusScript code rebuilds corrupted busytime.nsf file
Soft-code item names to facilitate LotusScript management
LotusScript agent automates selective mail file replication

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



Domino & Lotus Notes Security Solutions: Authentication, Antispam, Encryption and Antivirus
HomeTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersDomino IT Downloads
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 1999 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts