Home > Domino Tips > Developer > LotusScript > Dynamically update Lotus Notes rich-text fields using LotusScript
Domino Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

LOTUSSCRIPT

Dynamically update Lotus Notes rich-text fields using LotusScript


Amith Narera
11.20.2007
Rating: -4.40- (out of 5) Hall of fame tip of the month winner


Lotus Notes, Domino, Workplace and WebSphere tips and advice
Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


VIEW MEMBER FEEDACK TO THIS TIP
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
Related resources from SearchDomino.com:
Expert Advice: Copying a rich-text field with attachments to a Lotus Notes document

Tip: Modify a rich-text field in the UI without having to save and re-open

Tutorial: 30 LotusScript tips

LotusScript Reference Center

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 
DummyUIDoc
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 
Document
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
(DummyDoc,"DummyRT")
 
'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,"",
CurrentFilePath)
End Forall
End If
'COMMENT #######>You may also append 
an RT Item from any other document. eg.
%REM
Dim RTItemB As NotesRichTextItem 
Set RTItemB = DocB.GetFirstItem("RTItemName")
Call DummyRT.AppendRTItem(RTItemB)
%END REM
 
'COMMENT #######> Call this to commit all 
the RT Item Changes to the Document
Call DummyRT.Update 
  
'Here is the Trick
'******************************************************
**************************************
Set DummyUIDoc =  workspace.EditDocument(
True,DummyDoc)
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 

MEMBER FEEDBACK TO THIS TIP

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 SearchDomino.com 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.

Rate this Tip
To rate tips, you must be a member of SearchDomino.com.
Register now to start rating these tips. Log in if you are already a member.


Submit a Tip




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


RELATED CONTENT
LotusScript
Extracting attachments from a Lotus Notes rich-text field
Programmatically replace the design of Lotus Notes databases
Reading a binary field in an Oracle database with LotusScript
LotusScript equivalent of @Picklist for Lotus Notes
Launch large attachments within an email from a Notes database
How to find files on a hard drive or mapped network with LotusScript
Update the ACL from the Roles view with LotusScript
LotusScript agent moves tagged spam email to junk mail folder
Create a personalized greeting for Lotus Notes database users
Fail-safe rich-text validation using LotusScript

LotusScript
Extracting attachments from a Lotus Notes rich-text field
Programmatically replace the design of Lotus Notes databases
Reading a binary field in an Oracle database with LotusScript
LotusScript equivalent of @Picklist for Lotus Notes
Launch large attachments within an email from a Notes database
How to find files on a hard drive or mapped network with LotusScript
Update the ACL from the Roles view with LotusScript
LotusScript agent moves tagged spam email to junk mail folder
Set a value in a field existing in another Lotus Notes database
Create an automatic scheduled view export in Excel

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.

HomeNewsTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersDomino IT Downloads
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of technology-specific Web sites, events and magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Reprints  |  Site Map




All Rights Reserved, Copyright 1999 - 2008, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts