Retrieve field value from document in other db

Here’s my problem:

2 databases A and B

User opens document a (in db A) and clicks a button to create document b (in db B). The unique id of document b is returned and saved in document a (in order to create a hyperlink).

Does anyone know of a way to retrieve any field values from document b (at a later stage)?

Basically I would require to have a code which retrieves certain fieldvalues from document b everytime a button is pressed.

Any help would be greatly appreciated

B.

Subject: retrieve field value from document in other db

if you have the unid of the document you want, why not use the GetDocumentByUNID method ?

Subject: RE: retrieve field value from document in other db

I probably need a break, but this simple code just won’t work (type mismatch)

Sub Click(Source As Button)

Dim session As New NotesSession

Dim db As New NotesDatabase (“SERVER”,“DATABASE.nsf”)

Dim ws As New NotesUIWorkspace

Dim thisUIdoc As NotesUIDocument

Dim doc As NotesDocument

Set thisUIdoc = ws.CurrentDocument

unid = thisUIdoc.FieldGetText(“TIID”)

Set doc = db.GetDocumentByUNID(unid)

Dim tinum As String

tinum = doc.GetItemValue(“OrderNumber1”)

Messagebox(tinum)

End Sub

Subject: RE: retrieve field value from document in other db

Since you don’t have any error-trapping, I’m guessing you’re not aware that this line:

Set doc = db.GetDocumentByUNID(unid)

is erroring out because you haven’t actually opened db. (There are certain things you can do with an unopened database, like get its name or path, but you can’t get a view or document until the database is open.) You could handle this two ways:

Dim db as new notesdatabase(“”, “”)

Set db = session.getdatabase(“server”, “database.nsf”)

or 2)

Dim db as new notesdatabase(“server”, “database.nsf”)

call db.Open(“”, “”)

FYI, I’d recommend adding error-trapping to your code as a best practice.

Sub Click(Source As Button)

on error goto errhand

Dim session As New NotesSession

Dim db As New NotesDatabase (“SERVER”,“DATABASE.nsf”)

Dim ws As New NotesUIWorkspace

Dim thisUIdoc As NotesUIDocument

Dim doc As NotesDocument

Dim tinum As String

Set thisUIdoc = ws.CurrentDocument

unid = thisUIdoc.FieldGetText(“TIID”)

Call db.Open(“”, “”)

Set doc = db.GetDocumentByUNID(unid)

tinum = doc.GetItemValue(“OrderNumber1”)

Messagebox(tinum)

exit sub

errhand:

msgbox "Error at line " & erl & ": " & error

exit sub

End Sub

Subject: RE: retrieve field value from document in other db

Always get a Type Mismatch error on the messagebox, although the OrderNumber1 field is a text field.

Call db.Open(“”,“”) method tells me that the db is already opened.

only the Set db = session.getdatabase(“server”, “database.nsf”) seems to work.

B.

Subject: RE: retrieve field value from document in other db

GetItemValue always returns an array, so you need to use the (0) index or Join the values before you can messagebox them.

Subject: RE: retrieve field value from document in other db

Thanks, messagebox seems to work.

What would be the best method to write this value to a field in doc A?

Subject: RE: retrieve field value from document in other db

Assuming doc A is the currently-open UI doc:

thisUIDoc.document.fieldToSet = doc.OrderNumber1(0)

or

thisUIDoc.FieldSetText(fieldToSet, doc.OrderNumber1(0))