KeyDocumentByKey

Hi All,I’m having trouble with the simplest script that I’ve used before. The GetDocumentByKey is not getting a document. Any ideas???

Kari

Sub Initialize

Dim session As New NotesSession

Dim db As NotesDatabase

Dim view As NotesView

Dim lookupView As NotesView

Dim doc As NotesDocument

Dim newDoc As NotesDocument     



Set db = session.CurrentDatabase

Set view = db.GetView("EmpName04")

Set lookupView=db.GetView("EmpName05")



Set doc = view.GetFirstDocument     

counter@ = 0

While Not(doc Is Nothing)

	counter@ = counter@ + 1

	Print "Processing Document Number: " & Cstr(counter@)

	empName$ = doc.Name(0)

	title$=doc.Title(0)

	

	key=empName$

	Set newDoc = lookupView.GetDocumentByKey(key)    

	Do While Not ( newDoc Is Nothing )

		newDoc.Title=title$

		Call doc.PutInFolder("Duplicates")                             

	Loop

	Set doc = view.GetNextDocument(doc)    

Wend

End Sub

Subject: I do not think your problem is the GetDocumentByKey…

I think your problem is here: Set newDoc = lookupView.GetDocumentByKey(key)

	Do While Not ( newDoc Is Nothing )

		newDoc.Title=title$

		Call doc.PutInFolder("Duplicates")                             

	Loop

This loop will never end. I think you want:

	Set newDoc = lookupView.GetDocumentByKey(key)    

	If Not ( newDoc Is Nothing ) Then

		newDoc.Title=title$

		Call doc.PutInFolder("Duplicates")                             

	End If

Subject: KeyDocumentByKey

If the view changed (new hidden columns or someone removed the sort) then you’ll not get data, even with the best of code.

Collin

Subject: KeyDocumentByKey

Check your inner loop:GetDocumentByKey returns a single document, if any; It looks like you need GetAllDocumentsByKey istead, then process the collection returned.

Also:

Shouldn’t “Call doc.PutInFolder(“Duplicates”)” be “Call newdoc.PutInFolder(“Duplicates”)”?

Simeon