Notes 8 cannot access existing notes RichTextItems

For instance, try the following code, underneath a button, on a document that has a field called design_system_changes:

Sub Click(Source As Button)

Dim workspace As New NotesUIWorkspace

Dim uidoc As NotesUIDocument

Dim doc As NotesDocument

Dim domSession As New NotesSession

Set uidoc = workspace.CurrentDocument

Dim doc As NotesDocument

Dim rtitem As Variant

'.set value of doc…

Set doc = uidoc.Document

Set rtitem = doc.GetFirstItem( “design_system_changes” )

Call rtitem.AddNewLine( 1 )

Call rtitem.AppendText _

( “Book is 64 pages, full color.” )

Call doc.Save( False, True )

End Sub

Expected result: design_system_changes is set with the words

Book is 64 pages, full color.

Actual Result:

Nothing.

Subject: Don’t use a back-end save on a front-end document.

You must use NotesUIDocument.Save, not NotesDocument.Save, or else when you do save from the UI, you’ll overwrite your back-end changes. Also, please read about the NotesUIDocument.Refresh method’s first argument.

Subject: OK but…

But why have this example in the help file.Code below is directly from the help file for AddNewLine. This is what I adapated.

Be much better if they added a full instead of partial code.

I note that they are running a backend save, and it doesn’t mention the need to refresh the ui either.

Dim doc As NotesDocument

Dim rtitem As Variant

'…set value of doc…

Set rtitem = doc.GetFirstItem( “ProjectDescription” )

If rtitem.Type = RICHTEXT Then

Call rtitem.AddNewLine( 1 )

Call rtitem.AppendText( “Book is 64 pages, full color.” )

End If

Call doc.Save( False, True )

Subject: on help documentation and front-end/back-end

I note that they are running a backend save, and it doesn’t mention the need to refresh the ui either.That’s because the example wasn’t written with the assumption that there is a UI document. This would be appropriate code for a back-end agent.

It’s asking a lot of an example to expect it to cover all the possible situations in which you might try to use a function, including all the ones where you really shouldn’t. That’s more the job of the usage notes, I think.

I’ve written a little essay about working with NotesDocuments and NotesUIDocuments, which I’ve sent along to the doc team with the suggestion that they include it in the NotesUIDocument help document. No developers will read it, of course, once it’s in the documentation, but I do what I can. I posted a copy to my blog just now.

BTW, as I always point out when someone wants to correct the help docs, there’s a “feedback” link on each and every help doc where you can suggest a change, and we have staff assigned to read these and update the help.

  • Andre Guirard, IBM/Lotus Development

Useful blog: Best Practice Makes Perfect