Manage Learn to apply best practices and optimize your operations.

Validate rich text fields for attachments without saving the UI document

This tip describes how to validate rich text fields for attachments without saving the UI document.

Validation of rich text field on the UI poses a tricky situation, particularly when it is required to check if any attachments have been added to the field. This happens because the LotusScript doesn't get a handle to the embedded objects in a rich text field until the UI document is saved to the backend document. Thanks to the enhanced 'refresh' method of NotesUIDocument class in R5, this tricky problem can be solved with some simple code.

Here is the 'test' code and the steps to carry out the test...

  1. Add a button to a form that contains a rich text field named 'Body'
  2. Attach the following code to the button.
  3. Save the form and preview in Notes client.
  4. When you click on the button, it should pop-out a message indicating the number of attachments in the Body field.

Dim ws As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim doc As NotesDocument  
Set uidoc = ws.CurrentDocument
Set doc = uidoc.document
uidoc.refresh True  '<= here's the hero! The 'True' parameter 'transfers' all rich text items to the back-end document.
Dim rtitem As Variant
Dim embedObjs As Variant
Set rtitem = doc.getFirstItem("Body")
embedObjs = rtitem.embeddedObjects
Msgbox "There are " + Cstr(Ubound(embedObjs) + 1) + " attachments in 'Body' field"

Dig Deeper on Domino Resources - Part 6



  • Favorite iSeries cheat sheets

    Here you'll find a collection of valuable cheat sheets gathered from across the iSeries/ community. These cheat ...

  • HTML cheat sheet

    This is a really cool cheat sheet if you're looking to learn more about HTML. You'll find just about everything you every wanted ...

  • Carol Woodbury: Security

    Carol Woodbury