Richtext - the scourge of a Notes developer

Wednesday, March 12, 2014 at 5:50 PM UTC

Today I was at customer's site to correct the last few things in the application we deployed in the beginning of 2014. I had two tickets dealing with Richtext in normal documents. This application does not use XPages, only traditional web development usage.

I encountered a few issues regarding the handling of Richtext in Lotusscript. I twittered about it over the day, so you may noticed them. I'll try to recap both of them here.

Task 1: find and replace a string within a Richtext container with the RichtextNavigator

Prior to the following code we had to replace all line breaks with a string "<<NL>>". This was to also replace other placeholders with real values as this won't work in paragraphs containing line breaks. After replacing everything needed we just wanted to replace the "<<NL>>" with real line breaks like this:

Set rtnav = rt.CreateNavigator 
bFound = rtnav.FindFirstString ("<<NL>>",RT_FIND_CASEINSENSITIVE)
Set RTRange2 = RT.CreateRange
Do While bFound
rtrange2.SetBegin rtnav
rtNav.SetCharOffset (6)
rtrange2.SetEnd rtnav
rtrange2.Remove 
If Err Then Exit Do
rt.BeginInsert rtnav,False
rt.AddNewline 1,True
rt.EndInsert 
rt.update
 
bFound = rtnav.FindFirstString ("<<NL>>",RT_FIND_CASEINSENSITIVE)
Loop
 
Call rt.Compact

This one works fine unless the user is a "normal" user with "normal" rights, e.g. author or editor. I had no problems with it with manager access, but real users saw the <<NL>> text afterwards. Sometimes it replaced some of them, sometimes it replace all of them with... nothing! No line breaks, just an empty space. It was real unstable.

I found a way out of this: after the line "rt.update" I had to re-instanciate the navigator with

Set rtnav = rt.CreateNavigator

and everything worked fine for all users. Strange, isn't it?

Task 2: compose a mail in the backend (server side) and render a whole document with form design etc. to the mail body

No problem you might think? Yes is CAN be a problem. The script I coded runs within a container, a sandbox surrounded by "sub soandso - end sub" and is executed via the Execute statement. This seems to be the problem here. I cannot show you the real code as I am not on the real machine now but it was something like this:

dim sourceDoc as NotesDocument
set sourceDoc = getParentDocument(0)
dim mail as NotesDocument
set mail = db.createDocument
dim rt as new NotesRichTextItem(mail, "Body")
call sourceDoc.renderToRtItem(rt)

The last line got the server to crash! Here is the last breath it took and then disappearing to Nirvana:

But there is also a solution (a workaround in this case). You might never get into that trouble when not using the execute-environment/sandbox. I made a proof-of-concept with a server agent called directly on the server with similar code - no problems then. This will be my solution for tomorrow to solve the last issue in the customer's application.

So stay tuned, stay hungry, stay crazy to find the suitable solution for your problem Smile







Leave a comment right here