Rich text in UI

Maybe I misunderstood what this was supposed to do, but I thought that by calling NotesRichTextItem.Update, you forced the processing of all changes to the item without explicitly closing and reopening the ui document.

I have a document open in the UI, with an existing rich text field (yes, the field does actually exist on all documents, even if it’s empty - I ran a refresh agent that created the field, so it is available in the document

properties even if it’s never been used). I attach a document to the rich text field by clicking the paper clip smart icon. I have a button in the form that sends an email to an administrator notifying them of the attachment. I need to include a copy of the attachment in the email.

I had thought that by calling NotesRichTextItem.Update in my button code before using AppendRTItem, I would get the changes that were just made to the field (i.e. the attachment), but it isn’t happening. The email sends, but doesn’t include the attachment (or text, if I’ve just added text to the field.) If I physically close and reopen the document and click the button again, it works as expected.

Am I completely misunderstanding what Update does? Everyone was making such a big deal of the fact that in R6 you could work with rich text items without closing and reopening…

Here’s my code:

Sub Click(Source As Button)

  On Error Goto errhand

  Dim w As New notesuiworkspace

  Dim s As New notessession

  Dim db As notesdatabase

  Dim doc As notesdocument

  Dim mailDoc As notesdocument

  Dim body As notesrichtextitem

  Dim invoice As notesrichtextitem

  Dim prefDoc As notesdocument

  Dim plainText As String



  Set db = w.currentdatabase.database

  Set doc = w.currentdocument.document

  Set prefDoc = db.getprofiledocument("choicesForm")



  Set invoice = doc.getfirstitem("invoiceAttach")

  Call invoice.Update



  Call doc.Save(True, True)



  Set mailDoc = db.CreateDocument

  mailDoc.Subject = "New invoice to process for " & doc.Project(0)



  If mailDoc.hasItem("body") Then

        Set body = mailDoc.GetFirstItem("body")

  Else

        Set body = New NotesRichTextItem( mailDoc, "body")

  End If



  Call body.appendtext(s.commonusername & " has posted an invoice for

processing for " & doc.Project(0) & ". ")

  Call body.addnewline(2)

  Call body.appendtext("Here is a doclink to the actual document: ")

  Call body.appenddoclink(doc, doc.Program(0))

  Call body.addnewline(2)

  Call body.appendtext("Please open the document and create an AP

voucher.")

  If invoice.Type = RICHTEXT Then

        plainText = invoice.GetFormattedText( False, 0 )

        If plainText = "" And  Isempty(invoice.EmbeddedObjects) Then

              Goto finishSub

        Else

              Call body.AddNewLine(2)

              Call body.AppendText("Here is a copy of the invoice.")

              Call body.AddNewLine(1)

              Call body.AppendRTItem(invoice)

        End If

  End If

finishSub:

  mailDoc.Principal = "NotesMessenger"

  mailDoc.From = "NotesMessenger"

  mailDoc.SendTo = prefDoc.adminPerson



  Call mailDoc.Send(False)



  Msgbox "The Adoptions admin has been notified of the new invoice."

  doc.invoiceMailSent = Date

  Call doc.Save(True, True)



  Exit Sub

errhand:

  Msgbox "Process Invoice error at line " & Erl & ": " & Error

  Exit Sub

End Sub