Skip to main content
BlueMix free trial
 
developerWorks
AIX and UNIX
Information Mgmt
Lotus
New to Lotus
Products
How to buy
Downloads
Live demos
Technical library
Training
Support
Forums & community
Events
Rational
Tivoli
WebSphere
Java™ technology
Linux
Open source
SOA and Web services
Web development
XML
My developerWorks
About dW
Submit content
Feedback



developerWorks  >  Lotus  >  Forums & community  >  Notes/Domino 6 and 7 Forum

Notes/Domino 6 and 7 Forum

developerWorks

  

Sign in to participate PreviousPrevious NextNext


Andre Guirard 10.Aug.04 01:21 PM Lotus Notes
Applications Development All Releases Windows 2003; Windows 2000; Windows XP; Windows NT; Windows 95; Windows 98; Macintosh


I've seen this asked a lot and I haven't seen a clear and comprehensive answer, so I thought I should post it here. I hope it can be added to the FAQ.

The code sample below shows how to write LotusScript code that makes changes to a rich text field in a document that the user is editing, and displays those changes immediately on-screen, without saving the changes. This also works if you need to repeat other operations that only occur when a document is opened, e.g. evaluating section editor formulas and computed subform formulas.

Of course, you can make some rich text changes using the NotesUIDocument methods, but it's not possible to do important things like add paragraph breaks, table rows and file attachments in that way.

Points to note:
  • You can also use this for other applications that require the document be opened and closed but not saved, including repainting pass-thru HTML in the Notes client or recalculating subform formulas.
  • A drawback to this approach is that it actually does close and reopen the document window, so any form event code in the Queryclose, Queryopen, Postopen, etc will trigger, and the cursor will end up in the default field. Workarounds are of course possible; it's just a pain.
  • If you're already editing a document and there is a rich text field on the form, the rich text field already exists in Notes' memory, even if it's empty. You should not use CreateRichTextItem or New NotesRichTextItem to create another item with the same name. Instead, locate the already-existing item.
  • The existing rich text field is not loaded into the back-end document automatically when you get NotesUIDocument.Document. You must explicitly request it by calling NotesUIDocument.Refresh(True). This, however, will also trigger all your computed fields, input translation and validation functions. The input validations are especially a problem because they'll put up a validation failure dialog, which is inappropriate when you're not actually saving the document yet. The solution to this is to use @If(@IsDocBeingRecalculated; @Success; ...) in your input translations. You should be doing this anyway so that the user doesn't get error messages when they press F9 or if you have a keyword field that's set to refresh on keyword change.

Here's the code, which should work in Notes 5.0.2 and higher:

Dim wksp As New NotesUIWorkspace
Dim session As New NotesSession
Dim uidoc As NotesUIDocument, uidocNew As NotesUIDocument
Dim doc As NotesDocument
Dim rti As NotesRichTextItem
Dim strFieldname As String

Set uidoc = wksp.CurrentDocument
uidoc.Refresh True ' do this if the rich text field is editable, to get the current contents in case user has modified them.
Set doc = uidoc.Document  ' get the back-end document for the document open on screen.
strFieldname = uidoc.CurrentField ' remember the current field if any
Set rti = doc.GetFirstItem("fieldname") ' insert your fieldname here, generally "Body"

' Make your rich text changes here, for instance:
Call rti.AddNewLine(1, True)
Call rti.AppendText(Now & ": log entry.")
If session.NotesBuildVersion >= 190 Then
rti.Update ' ND6 and later
Else
Call doc.ComputeWithForm(True, False) ' caution, as this may erase some field values if you have @Db functions in formulas.
End If

doc.SaveOptions = "0" ' make it possible to close the document without a "do you want to save" prompt. If this is a mail-in doc you may need to set MailOptions="0" also to avoid being prompted.
Call uidoc.Close(True)
Set uidocNew = wksp.EditDocument(True, doc, , , , True)
Delete uidoc
uidocNew.Document.RemoveItem("SaveOptions")
If strFieldname <> "" Then uidocNew.GotoField(strFieldname) ' return focus to field that was current before.

Note: this will cause Queryclose, Queryopen, Postopen (and so on) form events to trigger. Also, uidoc.Refresh will execute computed field formulas and input validations, so you should write the validation formulas to not return @Failure unless @IsDocBeingSaved | @IsDocBeingSent is true.






Tip: How to update rich text in a d... (Andre Guirard 10.Aug.04)
. . RE: Tip: How to update rich text in... (Jennifer Rahn 14.Jul.05)
. . Dynamic HTML table with links that ... (Pavel A Sukhodo... 8.Aug.05)
. . RE: Tip: How to update rich text in... (Greg J Lorditch... 21.Oct.05)
. . RE: Tip: How to update rich text in... (Pavel A Sukhodo... 21.Jun.05)
. . Code correction for 6.5.4 (AJP FilmIT 8.Feb.06)
. . . . RE: Code correction for 6.5.4 (Marjan Nieuwlan... 15.Jun.06)
. . . . RE: Code correction for 6.5.4 (Christian cs So... 6.Nov.07)
. . . . RE: Code correction for 6.5.4 (christina rules... 12.Dec.08)
. . RE: Tip: How to update rich text in... (Roland Burgess 24.Apr.06)
. . . . RE: Tip: How to update rich text in... (Augusto Decoud 17.May.06)
. . . . . . RE: Tip: How to update rich text in... (Marjan Nieuwlan... 15.Jun.06)
. . BUG! (Steve Cochrane 17.Apr.07)
. . RE: Tip: How to update rich text in... (Alain Lapierre 29.Sep.08)
. . TY!!! How to update rich text in a ... (Jeremy W Deal 13.Jul.09)
. . Thank you! But what are possible wo... (Daniel Pincas 26.Aug.09)
. . . . RE: Thank you! But what are possibl... (Prashant S Arka... 1.Sep.09)
. . RE: Tip: How to update rich text in... (dinesh vellingi... 16.Jul.10)
. . . . RE: Tip: How to update rich text in... (Deepak Nair 20.Jul.10)
. . re: How to update rich text (Save C... (Paul M Ehrsam 20.Jun.11)
. . RE: Tip: How to update rich text in... (Aasha Chermugak... 3.Jan.12)
. . RE: Tip: How to update rich text in... (Trish McLaurin 30.Jul.12)
. . . . RE: Tip: How to update rich text in... (Athirah Foad 19.Jun.14)





  Document options
Print this pagePrint this page

 Search this forum

  Forum views and search
Date (threaded)
Date (flat)
With excerpt
Author
Category
Platform
Release
Advanced search

 Sign In or Register
Sign in
Forgot your password?
Forgot your user name?
Create new registration

 RSS feedsRSS
All forum posts RSS
All main topics RSS
More Lotus RSS feeds

Resources

 Resources
Forum use and etiquette
Native Notes Access
Web site Feedback

Lotus Support

 Lotus Support
IBM Support Portal - Lotus software
Lotus Support documents
Lotus support by product
Lotus support downloads
Lotus support RSS feeds

Wikis

 Wikis
IBM Composite Applications
IBM Mashup Center
IBM Connections
IBM Connections Cloud Developers
IBM Docs
IBM Forms
IBM Mobile Connect
IBM Sametime
IBM SmartCloud for Social Business
IBM Web Experience Factory
Lotus Domino
Lotus Domino Designer
Lotus Expeditor
Lotus Foundations
Lotus iNotes
Lotus Instructor Community Courseware
Lotus Notes
Lotus Notes & Domino Application Development
Lotus Notes Traveler
Lotus Protector
Lotus Quickr
Lotus Symphony
IBM Web Content Manager
WebSphere Portal

Lotus Forums


 Lotus Forums
Notes/Domino 9.0
Notes/Domino 8.5 + Traveler
Notes/Domino XPages development forum
Notes/Domino 8
Notes/Domino 6 and 7
IBM Connections
IBM Mobile Connect
IBM Sametime
IBM SmartCloud Notes
Lotus Enterprise Integration
Lotus Protector
Lotus Quickr
Lotus SmartSuite