DocLink not being set

I am testing with the below technique & can’t seem to get the docLink to be set. This is just a simple form…with one action button (code below) & a RichText field. I am attempting to chose a doc collection from as picklist & insert a docLink of each of those documents into the field on the current document. Can anyone locate where my error might be? Or is this technique no possible…it seems like it should be ok…

Thanks in advance for your help

Sub Click(Source As Button)

On Error Goto errorHandler 



Dim ws As New NotesUIWorkspace 

Dim ss As New NotesSession 

Dim curDb As NotesDatabase 

Dim profileDoc As NotesDocument 

Dim uidoc As NotesUIDocument 

Dim curDoc As NotesDocument 

Dim asCol As NotesDocumentCollection 

Dim asDoc As NotesDocument 



Set curDb = ss.CurrentDatabase 

Set uidoc = ws.CurrentDocument 

Set curDoc = uidoc.Document 





Set asCol = ws.PickListCollection(PICKLIST_CUSTOM, True, curDb.Server, curDb.FilePath,_ 

"ViewName",_ 

"Title",_ 

"Prompt") 



Dim richText As New NotesRichTextItem(curDoc, "FieldName") 

Dim arrIDs() As String 

Dim arrTypes() As String 

Dim cnt As Integer 

cnt = 0 



Set asDoc = asCol.GetFirstDocument 

Do While Not asDoc Is Nothing 

	

	Call richText.AddTab( 1 ) 

	Call richText.AppendText("before doclink") 

	Call richText.AppendDocLink( asDoc , "Document Link", "TEXT" ) 

	Call richText.AppendText("after doc link") 

	

	Set asDoc = asCol.GetNextDocument(asDoc) 

Loop 

done:

Exit Sub 

errorHandler:

Messagebox "Error" & Str(Err) & ": " & Error$ 

Resume done 

End Sub

Subject: *Do you have a default view in that database? It is required for AppendDoclink method to work.

Subject: RE: *Do you have a default view in that database? It is required for AppendDoclink method to work.

Yes, I do and one selected as a default view…can it just be any view though?

Subject: DocLink not being set

You cannot update richtext field on the fly.1. It is possible on QueryOpen event

  1. You should save and reopen document to see changes in the richtext field made by script

Subject: RE: DocLink not being set

I have tried a couple different methods without success:

moved code to perform docLinking to QuerySave Event, to QueryOpen Event…all getting handles on the “target” docs by using docUNID’s that were obtained from my button click from before.

Is there a field property perhaps that I need to be aware of? I just changed data type of field to Richtext…

This really shouldn’t be this hard should…gosh…I’m getting a complex.

Subject: RE: DocLink not being set

I think you’re missing the point – you can’t make changes to a rich text item on a document open to the UI. You need to do things in pretty much this order for the changes to be visible:

  1. if the user has the document open in edit mode, perform a UI document save in order to capture user changes;

  2. close the ui document in order to eliminate edit conflicts between your code and the user’s actions;

  3. make your back-end changes to the rich text item;

  4. save the back-end document; and finally

  5. re-open the document to the UI if desired.

The exact order of operations can change, especially if you use the SaveOptions field to control UI saving, but the essential element is this – the user can make changes OR your code can make changes, but you cannot have both at the same time. There’s a sort of an application/file relationship between the rich text editor (the UI field) and the rich text item on the document. Your code changes the file, but when the user saves the document he/she’s working on, those changes are overwritten.

Subject: RE: DocLink not being set

ko…that makes it a little more clear. I’ll work with it.

Thanks all for your help.

Subject: DocLink not being set

Jeff,

when working with rich text in the ui, in order to see what you have done, you have to close the document and then re-open it. you may also have to play with the saveOptions for the document.

In short though, yes you can have document links in a document created on the fly

john