Match value to multivalue

I would like to compare a value to a MultiValue. I have a list of names in view 1 with the corresponding ShortName. I have another view 2 with multiple users names (Multivalue).

I would like to compare the names in the view 1 to the multivalue names in the other view 2. I would have to walk though each value in the multivalue field and find the name match. When I find the name match I want to take the Shortname from the other view 1 and place it in another field in view 2.

Example:

View 1

John J Jones jonesj

Tom Davis davist

View 2

Fred reed, Tom Davis, Frank T Boone, John J Jones

My code to match no multivalue fields, what do

i need to do to modify this?

Dim workspace As New NotesUIWorkspace

Dim s As New notessession

Dim cdb As notesdatabase

Dim db As notesdatabase

Dim vew1 As notesview

Dim vew2 As notesview

Dim doc1 As notesdocument

Dim doc2 As notesdocument

Set cdb = s.currentdatabase

Set vew1 = cdb.getview("FANAB")

Set vew2 = cdb.getview("FA")

Set doc1 = vew1.getfirstdocument

Dim item As notesitem



Do While Not doc1 Is Nothing

	m_key = doc1.ShortName(0)

	Set doc2 = vew2.getdocumentbykey(m_key,True)

	If Not doc2 Is Nothing Then

		doc2.ShortName = doc1.Short_Name(0)

		doc1.MailAddress = doc2.FA(0)

		

		Set item=doc1.GetFirstItem("MailAddress")			

		Call doc1.save(True,False)

	End If

	Set doc1 = vew1.getnextdocument(doc1)

Loop



Call workspace.ViewRefresh

Subject: RE: Match value to multivalue

The (0) at the end when you read a field, is an array index. Leave off the (0) and you get back the whole array. Then you can loop thru the values in the array (e.g. using Forall) and look up each one. Use Break when you have updated the document. You’ll get better performance if you set AutoUpdate = False for both views.

I notice you forgot to use Option Declare. Always use Option Declare.

Subject: RE: Match value to multivalue

Can’t get it to workDoes anyone have any code that would work with my code?

Subject: RE: Match value to multivalue

Option Declare

Set vew1 = cdb.getview("FANAB")

vew1.AutoUpdate = False

Set vew2 = cdb.getview("FA")

vew2.AutoUpdate = False

Set doc1 = vew1.getfirstdocument

Dim item As notesitem

Dim keys As Variant



Do While Not doc1 Is Nothing

	keys = doc1.GetItemValue("ShortName") ' no (0)!

	Forall key In keys

		Set doc2 = vew2.getdocumentbykey(key,True)

		If Not doc2 Is Nothing Then

			doc2.ReplaceItemValue "ShortName", keys ' or keys(0), or keys(ubound(keys)), depending what you intended.

			doc1.ReplaceItemValue "MailAddress", doc2.GetItemValue("FA")(0)

			' I notice you modified both documents, not sure this is what you intended.

			' Set item=doc1.GetFirstItem("MailAddress")  why you want this line I do not know

			Call doc1.save(True,False)

			Call doc2.save(True,False) ' no point in modifying it if you don't save it.

			Exit Forall

		End If

	End Forall

	Set doc1 = vew1.getnextdocument(doc1)

Loop

If that doesn’t do what you want, then please describe more precisely what you want, and tell what it’s doing instead. We can’t do anything with “doesn’t work” since there are many ways something can not-work.