Attach docLink to new doc in another database using LotusScript

Dim session As New NotesSession

Dim db As NotesDatabase

Set db = session.CurrentDatabase

Dim workspace As NotesUIWorkspace

Set workspace = New NotesUIWorkspace

Dim uidoc As NotesUIDocument

Set uidoc = workspace.CurrentDocument

Dim doc As NotesDocument

Set doc = uidoc.Document

Dim CorpDB As NotesDatabase

Set CorpDB = session.GetDatabase(session.CurrentDatabase.Server,“FormsRequest.nsf”)

Dim rti As NotesRichTextItem

Set rti = New NotesRichTextItem(newDoc,“Body”)

Dim newdoc As NotesDocument

Set newdoc = New NotesDocument(CorpDB)

newdoc.Form = “PDF Project Request”

Call rti.AppendDocLink(doc,“”)

Call newdoc.CopyItem(rti,“RelatedRequest”)

Error:

You may not save a Document Link into this field unless the linked-to database is the current database.

Summary:

I have a document open. This is my uidoc. I need to create a new document in another database and I need to attach a link of my uidoc into the other database. The other database is FormsRequest.nsf. I’d like to know either what I’m doing wrong or an altogether better way to do this. Thanks!

Subject: Two questions come to my mind…

…with regard to your code:(1) newDoc is referenced before it is declared. Doesn’t the compiler throw an error?

(2) Why not create the “RelatedRequest” RT item straight ahead, instead of first creating a “Body” item and then copying it to “RelatedRequest”?

If you modify the code similar as in the example below, it should work.

Dim newdoc As NotesDocument

Set newdoc = New NotesDocument(CorpDB)

newdoc.Form = “PDF Project Request”

Dim rti As NotesRichTextItem

Set rti = New NotesRichTextItem(newDoc,“RelatedRequest”)

Call rti.AppendDocLink(doc,“”)

Subject: when RT item created straight ahead nothing happens

(1) You noticed that newdoc is referenced before it is declared. Nice catch! In my actual code newdoc is declared 1st. I copied pieces of larger code to the forum & this was a cut & paste error.

(2) You suggested I create my “RelatedRequest” RT item straight ahead. This is what I tried first and when I use your code which is almost exactly what I had nothing happens. The doclink I’m trying to insert doesn’t show up. Therefore, I’m trying to create the rich text item first then copy it to my field. This almost works, but not quite. I’m able to get the doclink inserted, but I get a bunch of pop-ups because Notes doesn’t like what I’m trying to do.

Thanks, Paul.

Subject: solved…needed Call notesRichTextItem.Update

(2)Dim rti As NotesRichTextItem

Set rti = New NotesRichTextItem(newdoc, “RelatedRequest”)

Call rti.AppendDocLink(doc,“”)

Call rti.Update

Call notesRichTextItem.Update

Processes all pending operations on a rich text item. Operations on a rich text item are queued for efficiency. The order and time of completion are not predictable. Use this method to ensure that processing is complete at a certain point. This method is useful when interacting with the front-end classes.