DEMENTED! - GetDocumentByKey Not working

Hi,

I have the below code being called from an XPage. The purpose of the code is to loop through selected Call Documents (numbers added to an edit box) and link the calls together…

The problem I am having is that getdocumentbykey is not working! I have changed the code to a DocCollection, but its still returning zero when the call does exist in the view. The first column of the view is sorted and when I search for the call number in the view it returns.

Can anyone shet any light on this. I have been driven demented by this and as you can see I am logging a lot - the call number before is correct with no spaces.

Please help :

%REM

Agent LinkCalls

Created Mar 16, 2010 by PMP Developer/GB/CPL/ClydePumpsLtd

Description: Comments for Agent

%END REM

Option Public

'Option Declare

Use “SequentialNumber”

Sub Initialize()

Dim s As New NotesSession

Dim db As NotesDatabase

Dim WebDoc As NotesDocument

Dim agent As NotesAgent

Dim item As NotesItem

Dim CallNo() As String

Dim strAction As String

Dim strDate As String

Dim strName As String

Dim beginningText As Variant

Dim rtnav As NotesRichTextNavigator

Dim LogAction As NotesRichTextItem

Dim OldLogAction As NotesRichTextItem

Dim strStatus As String

Dim NewDoc As NotesDocument

Dim OldDoc As NotesDocument

Dim strNewNum As String

Dim Callv As NotesView



Set db = s.CurrentDatabase

Set agent = s.CurrentAgent

Set WebDoc = db.GetDocumentByID(agent.ParameterDocID)

Set item = WebDoc.Getfirstitem("LinkCalls")

strP = item.Text

arr = Split(strP, ";")



MsgBox "----------------------------------------------------"

'MsgBox "/////////////////////////////////////////////////////"



For x = 0 To UBound(arr)

		ReDim Preserve CallNo(x) As String

		CallNo(x) = arr(x)

		MsgBox CallNo(x)

		strName = WebDoc.CurrentUser(0)

		strDate = CStr(Now)

		If x = 0 Then

			MsgBox "Loop No : " & x

			Set Callv = db.GetView("All Calls")

			Set OldDoc = Callv.Getdocumentbykey(CallNo(x),True)

			If Not OldDoc Is Nothing Then

				MsgBox "In Here 1"

				Set NewDoc = db.Createdocument()

				MsgBox "In Here 1.5"

				Call OldDoc.Copyallitems(NewDoc,false)

				MsgBox "In Here 2"

				strNewNum = GenerateSequentialNumber("FLS Call")

				MsgBox "In Here 3"

				NewDoc.SDNum = strNewNum

				MsgBox "In Here 4"

				Call NewDoc.save(True,False)

				MsgBox "In Here 5"

				Call db.Updateftindex(false)

				Set NewDoc = Nothing

				Set OldDoc = Nothing

				Set Callv = Nothing

			End If

		Else

			Call UpdateCalls(s, db, WebDoc, CallNo(x))

		End If

	MsgBox "Loop Here"

Next

End Sub

Sub UpdateCalls(s As NotesSession, db As NotesDatabase, WebDoc As NotesDocument, CallNo)

MsgBox "In Update Sub"

Dim v As NotesView

Dim callDoc As NotesDocumentCollection

Dim StrNum As String



Set v = db.Getview("All Calls By Number")

strNum = CallNo

MsgBox strNum



Set callDoc = v.Getalldocumentsbykey(strNum,False)

MsgBox "DOCUMENTS FOUND : " & callDoc.Count



'MsgBox "Call NO : " & CallNo

End Sub

Thank you.

F1H

Subject: Look at this

Not sure if this is the issue you are having but take a look at this concerning GetDocumentByKey and getDocumentByKey

http://www-01.ibm.com/support/docview.wss?uid=swg21424178

Subject: Thanks - But not sure if thats the issue

Hi,

Thanks for the quick reply…I am not getting that error message. Please see the log entry for the agent :

16/03/2010 15:04:43 HTTP Server: Agent message: ----------------------------------------------------

16/03/2010 15:04:43 HTTP Server: Agent message: SD10-01579

16/03/2010 15:04:43 HTTP Server: Agent message: Loop No : 0

16/03/2010 15:04:43 HTTP Server: Agent message: In Here 1

16/03/2010 15:04:43 HTTP Server: Agent message: In Here 1.5

16/03/2010 15:04:43 HTTP Server: Agent message: In Here 2

16/03/2010 15:04:43 HTTP Server: Agent printing: Number assigned: SD10-02396

16/03/2010 15:04:43 HTTP Server: Agent message: In Here 3

16/03/2010 15:04:43 HTTP Server: Agent message: In Here 4

16/03/2010 15:04:43 HTTP Server: Agent message: In Here 5

16/03/2010 15:04:44 HTTP Server: Agent message: Loop Here

16/03/2010 15:04:44 HTTP Server: Agent message:

SD10-01577

16/03/2010 15:04:44 HTTP Server: Agent message: In Update Sub

16/03/2010 15:04:44 HTTP Server: Agent message:

SD10-01577

16/03/2010 15:04:44 HTTP Server: Agent message: NO DOC FOUND

16/03/2010 15:04:44 HTTP Server: Agent message: Loop Here

16/03/2010 15:04:44 HTTP Server: Agent message:

SD10-01570

16/03/2010 15:04:44 HTTP Server: Agent message: In Update Sub

16/03/2010 15:04:44 HTTP Server: Agent message:

SD10-01570

16/03/2010 15:04:44 HTTP Server: Agent message: NO DOC FOUND

16/03/2010 15:04:44 HTTP Server: Agent message: Loop Here

Here is the updated code that created this entry :

%REM

Agent LinkCalls

Created Mar 16, 2010 by PMP Developer/GB/CPL/ClydePumpsLtd

Description: Comments for Agent

%END REM

Option Public

'Option Declare

Use “SequentialNumber”

Sub Initialize()

Dim s As New NotesSession

Dim db As NotesDatabase

Dim WebDoc As NotesDocument

Dim agent As NotesAgent

Dim item As NotesItem

Dim CallNo() As String

Dim strAction As String

Dim strDate As String

Dim strName As String

Dim beginningText As Variant

Dim rtnav As NotesRichTextNavigator

Dim LogAction As NotesRichTextItem

Dim OldLogAction As NotesRichTextItem

Dim strStatus As String

Dim NewDoc As NotesDocument

Dim OldDoc As NotesDocument

Dim strNewNum As String

Dim Callv As NotesView



Set db = s.CurrentDatabase

Set agent = s.CurrentAgent

Set WebDoc = db.GetDocumentByID(agent.ParameterDocID)

Set item = WebDoc.Getfirstitem("LinkCalls")

strP = item.Text

arr = Split(strP, ";")



MsgBox "----------------------------------------------------"

'MsgBox "/////////////////////////////////////////////////////"



For x = 0 To UBound(arr)

		ReDim Preserve CallNo(x) As String

		CallNo(x) = arr(x)

		MsgBox CallNo(x)

		strName = WebDoc.CurrentUser(0)

		strDate = CStr(Now)

		If x = 0 Then

			MsgBox "Loop No : " & x

			Set Callv = db.GetView("All Calls")

			Set OldDoc = Callv.Getdocumentbykey(CallNo(x),True)

			If Not OldDoc Is Nothing Then

				MsgBox "In Here 1"

				Set NewDoc = db.Createdocument()

				MsgBox "In Here 1.5"

				Call OldDoc.Copyallitems(NewDoc,false)

				MsgBox "In Here 2"

				strNewNum = GenerateSequentialNumber("FLS Call")

				MsgBox "In Here 3"

				NewDoc.SDNum = strNewNum

				MsgBox "In Here 4"

				Call NewDoc.save(True,False)

				MsgBox "In Here 5"

				Call db.Updateftindex(false)

				Set NewDoc = Nothing

				Set OldDoc = Nothing

				Set Callv = Nothing

			End If

		Else

			Call UpdateCalls(CallNo(x))

		End If

	MsgBox "Loop Here"

Next

End Sub

Sub UpdateCalls(CallNo)

MsgBox "In Update Sub"

Dim s As New NotesSession

Dim db As Notesdatabase

Dim v As NotesView

Dim callDoc As NotesDocument

Dim StrNum As String



Set db = s.CurrentDatabase

Set v = db.Getview("All Calls By Number")

strNum = CallNo

MsgBox strNum



Set callDoc = v.getDocumentByKey(strNum,True)

If callDoc Is Nothing Then

	MsgBox "NO DOC FOUND"

Else

	MsgBox "DOC FOUND!!"

End If



'MsgBox "Call NO : " & CallNo

End Sub

Thanks for your help.

Subject: Solved: NotesView GetDocumentByKey Not Working

Hi,

I just spent the past few hours with the same aggravation. I am using a flat, not categorized, view that includes all documents in the database so it has about 44,000 documents in the view. I thought I was hitting some undocumented maximum number of docs that the NotesView GetDocumentByKey() method could process but that was not correct.

Somehow, even though I could see the doc I wanted to access in the view, the NotesView GetDocumentByKey() method could not find it.

The solution was to change the view property “Show response documents in a hierarchy” and make it UNCHECKED. Upon closer inspection, I had learned that the doc I was trying to access had the $REF field so it was not treated as a main doc and that made a difference to GetDocumentByKey().