Manage Learn to apply best practices and optimize your operations.

Dynamically update Lotus Notes rich-text fields using LotusScript

Learn how you can dynamically update Lotus Notes rich-text fields using LotusScript code -- without having to fire all associated form events in the process.

Whenever a change is made to a Lotus Notes document in the back-end, the same change is reflected in the front-end document -- except the rich-text fields. For rich-text field changes, you have to close the front-end Lotus Notes document and open it again using the NotesUIWorkspace.EditDocument method. However, this ends up also firing all associated Lotus Notes form events. This tip overcomes this problem by allowing you to dynamically update the front-end rich-text fields without closing and re-opening the main Lotus Notes form.

For the sake of simplicity, I am appending the current Lotus Notes username, system time and attachments (as selected by the Lotus Notes user) to the rich-text field. The LotusScript code below also allows you to append rich-text item from another Lotus Notes document (commented in the code). You can modify it for your needs.

Here is an outline of how the LotusScript code works:

  • Create a dummy Lotus Notes document in the back end using the db.CreateDocument method.
  • Add a rich-text field to it.
  • Perform all the necessary actions on this rich-text field.
  • Open the Lotus Notes document in the front-end with a dummy form with just one rich-text field (with the same name as created in the second step above).
  • Place the cursor in this rich-text field, select all the text, and copy everything to the clipboard.
  • Close the dummy Lotus Notes form.
  • Go to the destination rich-text field on the main Lotus Notes form.

  • Paste everything from the clipboard.
  • Mission accomplished.

Here are the steps you'll need to attain the desired result:

  1. Create a new form. Name it "Dummy Form."
  2. Place a rich-text field, named "DummyRT" on it.
  3. Open your main Lotus Notes form where you'd like these updates to happen.
  4. Create a new Action button, and name it "Update RT Field." You may use the LotusScript code anywhere. For the sake of simplicity I am using it in a button.
  5. Select LotusScript as the coding language and paste the code given below into it.
Sub Click(Source As Button)
Dim workspace As New NotesUIWorkspace 
Dim session As New NotesSession  

'COMMENT #######> UiDoc represents the 
currently open Fron End document, where the rich 
text field exists. 
Dim uidoc As NotesUIDocument 

'COMMENT #######> Dummy UIDoc ---
needed by the code
Dim DummyUIDoc As NotesUIDocument 
Dim db As NotesDatabase 

'COMMENT #######> Back End version of 
Dim DummyDoc As NotesDocument  

'COMMENT #######>  RT Item in DummyDoc 
---From where you would be pulling the changes
Dim DummyRT As NotesRichTextItem 
Dim FilePath As Variant 
Set db = session.CurrentDatabase 
Set uidoc = workspace.CurrentDocument 
Set DummyDoc = db.CreateDocument 
'COMMENT #######> Set Fields for Dummy 
DummyDoc.Form = "Dummy Form" ' NOTE: It 
shud be dummy form, not your main form.
DummyDoc.SaveOptions = "0"
'COMMENT #######> Get the File path for 
the file to be attached
FilePath = workspace.OpenFileDialog(True,
"Select Files")
'COMMENT #######> Insert RT Field
Set DummyRT = New NotesRichTextItem
'COMMENT #######> Update the Field- as 
per your requirements
Call DummyRT.AppendText(session.
CommonUserName & " - ")
Call DummyRT.AppendText(Cstr(Now))
Call DummyRT.AddNewline(1)
'COMMENT #######>Embed Selected Files, 
if Any
If Not Isempty(FilePath) Then
Forall CurrentFilepath In FilePath
Call DummyRT.EmbedObject(1454,"",
End Forall
End If
'COMMENT #######>You may also append 
an RT Item from any other document. eg.
Dim RTItemB As NotesRichTextItem 
Set RTItemB = DocB.GetFirstItem("RTItemName")
Call DummyRT.AppendRTItem(RTItemB)
'COMMENT #######> Call this to commit all 
the RT Item Changes to the Document
Call DummyRT.Update 
'Here is the Trick
Set DummyUIDoc =  workspace.EditDocument(
Call DummyUIDoc.GotoField("DummyRT")
Call DummyUIDoc.SelectAll 
Call DummyUIDoc.Copy
Call DummyUIDoc.Close(True)
'COMMENT #######> Goto Main doc Rich Text 
Field (desitnation field)
Call uidoc.GotoField("RTF")
Call uidoc.Paste 

Messagebox "Process Completed Successfully.",
64, "Complete"
End Sub

Now -- with a click of this action button -- you can update the front end of your rich-text item in real-time without having to close and re-open the main Lotus Notes document. You can also apply the same logic to move contents of one rich-text item to the other rich-text item on the same form in real time -- without having to re-open the front end document. If you'd like to do that, this code will help you:

Call UIDoc.GotoField("FirstRT")
Call UIDoc.SelectAll 
Call UIDoc.Copy
Call uidoc.GotoField("SecondRT")
Call uidoc.Paste


This is an excellent tip that has benefited one of our applications, while simultaneously removing undue bottlenecks and hurdles. Auditing dynamic tables over to rich-text fields helps prevent users from saving Lotus Notes documents unnecessarily.
—Prasanna P.

Do you have comments on this tip? Let us know.

This tip was submitted to the tip library by member Amith Narera. Please let others know how useful it is via the rating scale below. Do you have a useful Lotus Notes, Domino, Workplace or WebSphere tip or code snippet to share? Submit it to our monthly tip contest and you could win a prize.

Related resources from

Dig Deeper on LotusScript

  • Favorite iSeries cheat sheets

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