PermaLink Validating Rich Text Fields01/10/2006
Lotusscript
One of major problem with Rich Text Fields is that changes made to them in the Notes UI are not visible in the back-end Notes document until after the change has been saved in the Notes UI. This makes validating that a Rich Text Field is not empty particulary difficult. Sure, you can check to see if the field contains a text value or not, as is described here on the IBM developerWorks site for Lotus Software.

But what if you need to verify that the Rich Text Field contains something, whether its text, a doclink, an attachment, an embedded object?

If your form validation is invoked within the form's Querysave event, it won't work due to the problem described above. However, you can check the Rich Text Field after the document has been saved in the Notes UI. So, you could run your validation code in the Postsave event, or in an agent called by a button that performs the save. For more details on how to do this, click Read More below...

If you want to validate your Rich Text Field from within a LotusScript agent, you can invoke the agent after your document has been successfully saved. The easiest way to do this is to check to see if @Command ( [FileSave] ) returns true:

@If ( @IsDocBeingEdited; ""; @Command ( [EditDocument] ) );
FIELD NextStatus := "Ready for Publication";
saved := @Command ( [FileSave] );
@If ( saved; @Command ( [ToolsRunMacro]; "(ValidateForm)" ); "" )

In the agent, you can invoke a function like the one I've included below in your code like this:
Dim body As NotesRichTextItem Set body = doc.GetFirstItem ( "Body" ) If ( richTextFieldEmpty ( body ) ) Then If ( uidoc Is Nothing ) Then Else Msgbox "Please enter the Content", MB_OK + MB_ICONSTOP, "Field Contains Incorrect Value" Call uidoc.GoToField ( "Body" ) End If validateRequiredFields = False Exit Function Else Print "Rich Text Field not empty" End If

The richTextFieldEmpty() function below first verifies that the Rich Text Field passed as a variable isn't Nothing. This will be true if the document hasn't been saved yet. If the Rich Text field isn't Nothing, the code then check to see if it contains any of the data types that you can possibly add to a rich text field. If the Rich Text Field contains something, the function returns True, signifying that the Rich Text Field is indeed empty. For all other situations, the function returns False. While this all seems like a lot of effort to do something simple, its necessary until changes made to Rich Text Fields via the Notes client are reflected immediately in the back-end document.
Function richTextFieldEmpty ( rti As NotesRichTextItem ) As Boolean Dim rtNav As NotesRichTextNavigator On Error Goto errorHandler richTextFieldEmpty = False If ( rti Is Nothing ) Then Print "Rich Text Field does not exist" richTextFieldEmpty = True Exit Function End If Set rtNav = rti.CreateNavigator If ( rtNav.FindFirstElement ( RTELEM_TYPE_TABLE ) ) Then Print "Table found in rich text field" Exit Function End If If ( rtNav.FindFirstElement ( RTELEM_TYPE_TEXTRUN ) ) Then Print "Text run found in rich text field" Exit Function End If If ( rtNav.FindFirstElement ( RTELEM_TYPE_TEXTPARAGRAPH ) ) Then Print "Text paragraph found in rich text field" Exit Function End If If ( rtNav.FindFirstElement ( RTELEM_TYPE_DOCLINK ) ) Then Print "Doclink found in rich text field" Exit Function End If If ( rtNav.FindFirstElement ( RTELEM_TYPE_SECTION ) ) Then Print "Section found in rich text field" Exit Function End If If ( rtNav.FindFirstElement ( RTELEM_TYPE_TABLECELL ) ) Then Print "Table cell found in rich text field" Exit Function End If If ( rtNav.FindFirstElement ( RTELEM_TYPE_FILEATTACHMENT ) ) Then Print "Attachment found in rich text field" Exit Function End If If ( rtNav.FindFirstElement ( RTELEM_TYPE_OLE ) ) Then Print "OLE object found in rich text field" Exit Function End If richTextFieldEmpty = True endOfCode: Exit Function errorHandler: displayError ( Getthreadinfo (1) ) Error Err, Error$ '-- Throw Error back to invoking code Resume endOfCode End Function
This LotusScript was converted to HTML using the ls2html routine,
provided by Julian Robichaux at nsftools.com.

Comments :v

1. Eric Numeric03/28/2010 12:41:49 PM


How to validate for a Horizontal Rule in Rich Text? I'd like to find a way to capture all text up to the next Horizontal Rule found in a rich text field. Any ideas?




2. Domino05/21/2010 06:17:40 AM


Very good tip.




3. Jim Romaine04/12/2011 12:54:42 PM


Thanks for the tip!




4. Nitesh07/14/2011 05:43:11 AM


Hey about validation rich text in UI document?




Credits
NuTechs Powered by Domino
Search
Calendar
February 2012
Su
Mo
Tu
We
Th
Fr
Sa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
Monthly Archive
Get Real, Detroit!
Real Detroit Weekly
SWARM
Service
With
A
Rapid
Motion


-- old Rally's Hamburgers credo
Lotus Domino ND6 RSS News Feed RSS Comments Feed Podcast Feed Geo URL netcraft RSS Validator Lotus Geek Chris. A. Brandlehner Open Notes Picture Database OpenNTF CoComment Integrated BlogSphere
By Category
The BlogRoll
About
Contact Me
Contact me, Michael Sobczak, using this e-mail address:

my first initial my last name at Yahoo dot com
Recent Entries
No Recent Blogs
Powered by
Blogsphere