Normally, updating RichTextFields in an opened IBM Notes document requires saving, closing and then reopening the document. If you use the RichTextField to attach a file to the document even after doing all this closing and reopening, it is not guaranteed that the attachment is inserted where you want it to be. Another problem that is implicated with this is the necessity to save documents you do not want to save, yet.

Fortunately, there is an undocumented method in LotusScript that enables us to update RichTextFields on unsaved UIDocuments without the need for saving and reopening them.

It's called

NotesUIDocument.ImportItem( tmpDoc As NotesDocument, RichTextItem As NotesRichTextItem)

and it is part of in the NotesUIDocument class.

 

Explanation standard method:

The standard method to embed files or document links etc. into RichTextFields is the use of

NotesRichTextItem.embedObject

 

Example Code:

    Dim ws As New NotesUIWorkspace
    Dim db As NotesDatabase
    Dim doc As NotesDocument
    Dim rtitem As NotesRichTextItem
    
    Set doc = ws.CurrentDocument.Document
    Set rtitem = New NotesRichTextItem(doc, "RichTextField")
    Call rtitem.EmbedObject( EMBED_ATTACHMENT, "", "C:\Desktop\Document.docx")

 

Fig. 1: Notes form with buttons for the standard method and our workaround for attaching files in the RichTextField

 

After using the standard method the problems stated above become obvious. When the document is saved and reopened the file is attached at the end of the document, but not in the RichTextField where it should be.

Fig. 2: Result of the standard method EmbedObject of LotusScript

 

Explanation workaround:

Now we will use the ImportItem method.

 

Example Code:

    Dim sess As New NotesSession
    Dim ws As New NotesUIWorkspace
    Dim db As NotesDatabase
    Dim tmpdoc As NotesDocument
    Dim rtItem As NotesRichTextItem
    Dim uiDoc As NotesUIDocument
    
    'uiDoc contains the RichTextField we want to import our file into             
    Set uiDoc = ws.CurrentDocument
    
    'Create a support NotesDocument (tmpDoc)       
    Set db = sess.currentDatabase
    Set tmpdoc = db.CreateDocument
    
    'Create a RichTextItem on the support document to embed the desired file into
    Set rtItem = New NotesRichTextItem(tmpdoc, "RichTextField")
    
    'embed the desired file into the created RichTextItem
    Call rtItem.EmbedObject( EMBED_ATTACHMENT, "", "C:\Desktop\Document.docx")
    Call rtItem.update
    
    '!!Using computeWithForm ensures that the attachment is completely embed into the RichTextField before
    'we try to import it into our uiDoc. It works even though we have no form specified!!

    Call tmpdoc.ComputeWithForm(False, False)
    
    'Put Cursor into the RichTextField --> precondition for the file's import
    Call uiDoc.GoToField("RichTextField")
    
    'finally import the desired file into the RichTextField on the uiDoc.
    Call uiDoc.ImportItem(tmpDoc, "RichTextField")

 

Fig. 3: Result of the workaroung method ImportItem

 

As you can see, right after using the workaround button, the file is attached into the RichTextField of our opened document as desired. No saving and reopening needed!

!Please keep in mind that this workaround method is undocumented an could be removed from LotusScript by IBM!
 
I hope this workaround helped you as much as it helped me!
If you have any questions or suggestions do not hesitate to contact us.
 

 

Neues vom ITWU-Blog

Unsere ITWU Simple Integration Engine – An einer Stelle konfigurieren und mit dem gängigen Standard per REST-Aufruf ganz „ISIE“ überall nutzen! - Weiterlesen
ITWU-Projektvorstellung: Die kluge Scan-Lösung - Automatisiert Lieferscheine scannen und prozessintegriert verarbeiten mit dem Canon Scan-Import - Weiterlesen
Das neue HCL Download-Portal My HCLSoftware (MHS), EOS Domino V11 und Sametime V11.5 - Weiterlesen
HCL Lizenz Update: Umstellung auf Complete Collaboration Lizenzen (CCB), EOM und EOS für alte Lizenztypen und Änderungen der jährlichen Preissteigerung - Weiterlesen
Update-Info: HCL Notes Domino 14 Fix Pack 1 - Weiterlesen
Mit ITWU Simple Signature automatisch generierte HTML-Mailsignaturen für HCL Verse und Notes erstellen - Weiterlesen
ITWU-Projektvorstellung: Digitale Werkszeugnisse automatisch erzeugen, standardisiert und transparent - so geht smarte Qualitätssicherung! - Weiterlesen
 zum Archiv