getDocumentByKey

Hi Guys,I have some an action button in a view with some lotus script.

The lotus script needs to find a document in a view, I have got the view (confirmed in the debugger) but when I execute getdocumentbykey it returns no documents.

  • The view is categorized

  • the key i am searching on is real (line before has a messagebox which prints the value)

Any ideas on what else I could try to make this work?

I have also checked what is in the messagebox with ctrl-f in the view and it comes up wit a document.

Thanks

P

Subject: Post your code

Subject: code

Yeah the view is sorted and the first (and only) column has the field i’m trying to search on.

here is the code.

Sub Click(Source As Button)

Dim workspace As New NotesUIWorkspace

Dim session As New NotesSession

Dim uidoc As NotesUIDocument

Dim db As NotesDatabase

Dim view As NotesView

Dim farmDoc As notesdocument

Dim farmName As Variant



'get DB

Set db = session.CurrentDatabase

Set view = db.GetView("($FarmByName)")



'get current workspace

Set uidoc = workspace.CurrentDocument

Dim farmID As Variant

Dim shedID As Variant



'get fields from current form

farmID = uidoc.FieldGetText("HiddenSCID" )

shedID = uidoc.FieldGetText("SCShed")

farmName = uidoc.FieldGetText("SCFarm" )



'double check we have the right names

Messagebox(uidoc.FieldGetText("SCFarm" ))

Messagebox(farmName)



'get the doc

Set farmDoc  = view.GetDocumentbyKey(farmName)



'error checking

If Not (farmdoc Is Nothing) Then

	Set uidoc = workspace.ComposeDocument( "", "", "Delivery")

	Messagebox("Created new doc")

	Messagebox( farmDoc.GetItemValue("FarmHiddenID") )

Else

	Messagebox("didn't get farm doc")

End If

End Sub

Subject: not variant

surely the key to to getdocumentbykey should be a string, not a variant.

Subject: view refresh / sorted col

Just some basic questions:- is the first column in the view really sorted? (not the first visible column, but the very first col in design (in case there are hidden cols in the view))

If the categorized col doesn’t work, create a hidden, sorted (but not categorized) col as first col.

  • Is the view index up to date? If you recently created the doc, the getdocbykey might not work yet. Try a view.refresh before getdocbykey

Subject: Some code to try.

Suggest you try the following before you set the farmDoc.

farmName = farmName.text

from you code you should not have to do this. But I think, it worth a try.

also go for this.

Set farmDoc = view.GetDocumentbyKey(farmName, True)

Subject: fun and games

Thanks for your help guys,

I checked the sort/cat of the view that is fine.

I changed the variant for the key to a string

Eventually I found the problem it was that the view was hidden with ($viewname). This is wierd why can’t my code see a hidden view?

Cheers

P

Subject: Sorry if you know this already

is the key in the first column, is the column sorted?