Insert RichText into RichText with LotusScript – Chapter 2

In an earlier post I wrote about how to insert richtext from another document into a specific position in an exiting richtext item using DXL. This solution works fine but has a few limitations. One of this limitations is the handling of attachments and embedded objects.

So I was looking for another solution. I tried to use LotusScript but due to some missing methods there is no way to achive the goal.

Then I searched the C++ API and found

LNSTATUS Insert( const LNRichText &richtext, LNRTCursor *cursor )

This was exactly what I was looking for. I wrote a small console application to test this method. The function did exactly what it is supposed to do.

Using the

LNSTATUS GotoFirst( const LNString &searchstring )

method, it is possible, to insert the richtext at a specific position that can be defined by a placeholder. The placeholder can be of any name.

Insert Richtext - the placeholder

To delete the placeholder before inserting the replacing content, I use

rtTarget.Delete( &cursor, sizeof( InsertionPoint ));

I guess this is what IBM does when you use the FindAndReplace method of the NotesRichTextRange class. But with this metod you can replace text only. Replacing a string with richtext is not supported. I wonder, why IBM does not enhance this method. In my oppinion this is not very hard to do; as I stated before, the Notes API already has this functionality.

After a few more tests with attachments and embedded objects, I put all this stuff into an DLL. Now the function can be used from inside LotusScript. I decided to provide this new functionality as an DLL because all of my attempts to create an LSX ( using the LSX toolkit ) constantly crashes my client. Even with some help from Bill Buchan and Benjamin Langhinrich I was not able to build a stable function. Maybe i will succeed some day …

To use the InsertRichTextItem function from LotusScript, you have to copy “rt.dll” to your notes executable directory. Since the function uses the C++ API, you have to copy “lcppn70.dll”, too. I have created and tested the function with Notes 7.0.1, but it should work in former versions of Notes as well.

In the Declaration section of your Lotus Script put the following lines

Declare Function InsertRichTextItem Lib "rt" (_
Byval dbServer As String,_
Byval dbPath As String,_
Byval lngSourceNoteID As Long,_
Byval strSourceRTField As String,_
Byval lngTargetNoteID As Long,_
Byval strTargetRTField As String,_
Byval InsertionPoint As String) As String

The function is called as follows

strRet = InsertRichTextItem ( DB_SERVER, DB_FILE,  SourceNOTEID, "Body", TargetNOTEID, "Body","")

The function returns “OK” when completed successfully, otherwise it throws an error.

Sub Click(Source As Button)

	Dim s As New NotesSession
	Dim db As NotesDatabase
	Dim col As NotesDocumentCollection
	Dim doc As NotesDocument

	Dim SourceDoc As NotesDocument ' contains the richtext to be inserted
	Dim TargetDoc As NotesDocument ' insert RT here

	Dim rtItem As NotesRichTextItem
	Dim retval As Integer

	Set db = s.GetDatabase( DB_SERVER, DB_FILE)
	Set col = db.AllDocuments
	Set SourceDoc = col.GetNthDocument(2) ' SecondDocument
	Set TargetDoc = col.GetNthDocument(1) ' FirstDocument

	Dim SourceNOTEID As Long
	Dim TargetNOTEID As Long

	' Convert NOTEID from HEX to Long
	TargetNOTEID = Val("&H" + TargetDoc.NoteID)
	SourceNOTEID = Val("&H" + SourceDoc.NoteID)

	Msgbox InsertRichTextItem ( DB_SERVER, DB_FILE,  SourceNOTEID, "Body", TargetNOTEID, "Body","")

End Sub

Attached you’ll find a sample database. The necessary files are included in the “first document” – doc.

If you find this function useful, pls. let me know.


Insert a RichTextItem into another RichTextItem

As I posted before, IBM does not provide us with a method to insert content from one RichTextItem to another RichTextItem. I’m not talking about AppendRTItem … And it seems that nobody in the Notes Community has a solution for this.

Oh, yes, Ben Langhinrichs has a solution. But I’m not talking ’bout MIDAS. I did some research today and I think that it could be done using native Notes. Keywords are: DXLExporter, DXLImporter, Stream, string operations.

Using native Notes capabilities, I am able to replace a “TAG” with content of the according RTItem from another document.

… To be continued 🙂

For german native speakers, there is a posting on for this topic

RANT: How to solve an SPR – the IBM way

Have you ever tried to INSERT a RichTextItem into an existing RichTextItem instead of appending it ?
Let’s see how we could accomplish this. Actually there is no explicit method in the NotesRichText class to insert an item, but let’s see what the AppendRTItem method could do for us.

Oh, YES, here it is … right from the designer help ( version 6.5.1 ):

By default the insertion occurs at the end of the item. You can change the insertion point with BeginInsert and EndInsert.

This is easy, here is the code

Dim ses As New notessession
Dim db As NotesDatabase
Dim col As notesdocumentcollection
Dim doc As  NotesDocument
Dim rtitem2 As NotesRichTextItem
Dim rtitem1 As NotesRichTextItem
Dim rtnav As NotesRichTextNavigator

Set db=ses.CurrentDatabase
Set col=db.unprocesseddocuments
Set doc=col.GetFirstDocument

Set rtitem1 = doc.getfirstitem("Body")
Set rtitem2 = doc.getfirstitem("RTF")

Set rtnav = rtitem.CreateNavigator
Call rtnav.FindNthElement(RTELEM_TYPE_TEXTPARAGRAPH,1)

Call rtitem1.BeginInsert(rtnav)
Call rtitem1.addnewline(1)
Call rtitem1.AppendRTItem(rtitem2)
Call rtitem1.EndInsert
Call, True)

But what is this ? When you execute the code you’ll get an error message: “Method is not available.”

Hmm, do a search on the Lotus Notes KnowledgeBase and you’ll find this entry. And you can see in the document that there is an SPR# LGAA5N6FHT. But , huuuh, what is that ?

and was determined not to be a software problem. Notes and Domino are functioning as designed.

Does the documentation does not implies that it IS possible ? OK, it takes some time to code a new function and do all the quality stuff ( the KB document ist from the year 2004 as well as the mentioned SPR ) . Maybe they built it into the Notes 7 codestream.

But, NO WAY !!! Instead of having it got to work they just changed the designer help.

The insertion occurs at the end of the item. AppendRTItem cannot be called after BeginInsert.

IBM. please don’t tell me that ist is not possible to build this function !!! You’ve had 2 years. Instead of NEW classes and methods and stuff you should rather finish the coding of already intended methods in existing classes.

If you are not able to do the coding, please ask Ben Langhinrichs. He is able to solve the problem. And inserting RTItems the same way as inserting pure text after BeginInsert is a function that is needed, indeed.

I’ll hope tha some of the new guys at IBM will listen to the customers needs.