Hide Empty Rich Text Field in Lotus Notes

The problem is very simple: I want to hide a Rich Text field (RTF) if it is empty and show it if it has something in it, in my case one or more attachments. In Lotus Notes a Rich Text Field will not evaluate to empty even if it is emtpy so using a common Hide-When forumula such as MyRTF=”” will not work and you can only use @Formulas.

The solution:

1) Create a new Numeric field, Computed for Display, Hidden, and with Value set to @ThisValue (or HideMyRTF if you are using an earlier release than ND6)  Lets call this field HideMyRTF in this example.

2) Set the Hide-When formula of your existing Rich Text Field – lets call it MyRTF in this example – simply to HideMyRTF (meaning if HideMyRTF is True then hide MyRTF)

3) Add some LotusScript using the NotesRichTextItem EmbeddedObjects property to the Forms QueryOpen event. This will check if there are attachments or text in the field:

Dim rtitem As NotesRichTextItem
Set rtitem = source.Document.GetFirstItem( "MyRTF" )
If Isempty(rtitem.EmbeddedObjects) And Trim(rtitem.Text) = "" Then
    source.Document.HideMyRTF = 1
Else
    source.Document.HideMyRTF = 0
End If

That’s it.

It was a long time since I did any Lotus Notes development so I’m a bit rusty. I’m sure I’ve come up with this or a similar solution in the past but I could not find any when searching so I had to start from the beginning.

This was for an existing app that has been around for quite a few years so there is no way for me to control anything from the beginning. I guess I could have used an agent to set some stuff but this would most likely cause tons of replication conflicts as there are tens of thousands of documents, still being updated by users and replicated across several servers.

Done with a Lotus Notes 7.02 client (I told you it’s been a while…) but should work on older and newer releases.

2 comments

  1. this almost worked for me. I’m getting ‘object variable not set’ the first time that i open a new form. do u have any suggestions?

  2. I too am getting the same error that Judy mentioned. After the document has been saved and edited again, it works fine. Not sure if this blog gets checked but I would love to see an update on this functionality.

Leave a Reply to Judy Cancel reply

Your email address will not be published. Required fields are marked *