AppendDocLink question

My customer wants to have the application create a link to another document. While the below code produces no errors, neither does it produce a document link anywhere on the current document. Any constructive help is greatly appreciated as to why this is not working. The end user has DocA opened and clicks on an action bar button that has

@Command([ToolsRunMacro]; “(LinkToDocB)”)

The (LinkToDocB) agent is as follows

On Error Goto errHandle

Dim s As New NotesSession

Dim db As NotesDatabase

Dim cardb As NotesDatabase

Dim carview As notesview

Dim cardoc As NotesDocument

Dim ws As New NotesUIWorkspace

Dim carnum

Dim thisdoc As NotesDocument

Dim rtitem As NotesRichTextItem

Set db=s.CurrentDatabase

'Have end user select the DocB to link

carnum = ws.PickListStrings(PICKLIST_CUSTOM, False, db.Server, “fullfilepath”, “LinkToDocA”, “Link to DocB”, “Select the DocB to link”, 1)

If carnum(0)<>“” Then

Set cardb = s.GetDatabase(db.Server, “fullfilepath”)

Set carview =cardb.GetView(“LinkToDocA”)

'Get ahold of the DocB they selected

Set cardoc = carview.GetDocumentByKey(carnum(0))

Set thisdoc=ws.CurrentDocument.Document

Set rtitem = thisdoc.GetFirstItem(“linkedtoDocA”)

'Create a link to the DocA on this document

Call rtitem.appenddoclink(cardoc,"Click to open DocA " & carnum(0), "Click to open DocA " & carnum(0))

Call thisdoc.Save(True, False)

If Not cardoc.IsUIDocOpen Then

If cardoc.HasItem(“linkedtoDocB”) Then

Set rtitem = cardoc.GetFirstItem(“linkedtoDocB”)

Else

Set rtitem = cardoc.CreateRichTextItem(“linkedtoDocB”)

End If

'Create a link to this document on the DocA if no one is in it

Call rtitem.AppendDocLink(thisdoc, "Click to open DocB " & thisdoc.ReqNum(0), "Click to open DocB " & thisdoc.ReqNum(0))

Call cardoc.Save(True, False)

End If

Else

Msgbox “No link established”

End If

I realize all this should be working on the backend doc, and I am closing and reopening the UIDoc to try to view the changes and they are not there. Funnily enough, the link on DocB is there. Thank you.

Subject: AppendDocLink question

I would suggest you use ‘PickListCollection’ instead of ‘PickListStrings’. PickListCollection returns you a document collection handle which you can easily get the selected document from instead of performing another lookup to find it

Subject: RE: AppendDocLink question

Alex,Thank you for the suggestion. While that does make obsolete the second trip to the server to search, it does not correct my original issue in that the first doc link on the current document is not created. Below is the updated code. Any and all constructive help is greatly appreciated to figure out how to get a link to DocB onto the current document (DocA).

On Error Goto errHandle

Dim s As New NotesSession

Dim db As NotesDatabase

Dim cardoc As NotesDocument

Dim ws As New NotesUIWorkspace

Dim cn As NotesDocumentCollection

Dim thisdoc As NotesDocument

Dim rtitem As NotesRichTextItem

Set db=s.CurrentDatabase

'Have end user select the DocB to link

Set cn = ws.PickListCollection(PICKLIST_CUSTOM, False, db.Server, “fullfilepath”, “LinkToDocB”, “Link to DocB”, “Select the DocB to link”)

If cn.count > 0 Then

Set cardoc=cn.GetFirstDocument

Set thisdoc=ws.CurrentDocument.Document

If thisdoc.HasItem(“linkedDocB”) Then

Set rtitem = thisdoc.GetFirstItem(“linkedDocB”)

Else

Set rtitem = thisdoc.CreateRichTextItem(“linkedDocB”)

End If

'Create a link to the DocB on this document

Call rtitem.AppendDocLink(cardoc, "Click to open DocB " & cardoc.ReqNum(0), " " & cardoc.ReqNum(0) & " ")

Call rtitem.AddNewline(1)

Call thisdoc.Save(True, False)

If Not cardoc.IsUIDocOpen Then

If cardoc.HasItem(“linkedLAR”) Then

Set rtitem = cardoc.GetFirstItem(“linkedDocA”)

Else

Set rtitem = cardoc.CreateRichTextItem(“linkedDocA”)

End If

'Create a link to this document on the DocB if no one is in it

Call rtitem.AppendDocLink(thisdoc, "Click to open DocA " & thisdoc.ReqNum(0), " " & thisdoc.ReqNum(0) & " ")

Call rtitem.AddNewline(1)

Call cardoc.Save(True, False)

End If

Else

Msgbox “No link established”

End If

Thank you.

Subject: RE: AppendDocLink question

Since it’s the UIDocument you’re having a problem with try adding the following lines of code near the end of the formula:

If ws.CurrentDocument.EditMode Then

Call ws.CurrentDocument.Reload

Call ws.CurrentDocument.Refresh(True)

End If

This will force the current uidocument to be reloaded from changes made to its corresponding backend document. It’s possible that the changes you’re making in the backend are being lost when you save & close the document. The above code should get around this.

Let me know how it goes.

Alex

Subject: RE: AppendDocLink question

If I remember rightly - changes to RT Fields need the document to close and reopen before any changes can be seen - I don’t think reload will work.

OP - when you code finishes can you close the current document NOT saving it and then reopen it - can you now see the doclink? if so you need to alter your script to close and reopen the document

Subject: AppendDocLink question

There are lots of threads about AppendDocLink here.Most of them suggested, I think, that in order for AppendDocLink to work your db needs to have a default view.

Hope this helps