Rich Text Frenzy

Lotus Notes logoI’ve been a Notes/Domino Developer for almost 4 years now yet there are still some things in the hodgepodge of Notes/Domino development that makes me sit down and take a closer look at the situation. Sure there’s notes.net but just the same I’d still nudge the old cliché in saying I’m still not perfect.

Take for instance the recent requirement for something I was working on. Given a Notes UNID of a source document, I was to copy attachments to a destination document. It seemed pretty much a straightforward coding strain for the fingers but somehow after a couple of hours tweaking the code I was able to come up with so far, I knew I had to look elsewhere so that I can enjoy the rest of the day like the typical yuppie does.

What made it somewhat difficult was that changes to the rich text field don’t show up in Notes until after it was saved, (or at least what I was made to believe in.) This and the number of times I’ve had to wrestle with that “Do you want to save” Notes prompt and getting the attachment to appear on the RTF itself got me looking at the forum. My initial search at IBM’s developer forum yielded stuff which threaded the path to where my initial output went through: copy from the destination RTF, save the document, re-open the document. What if after successfully getting the attachment in the RTF, the user doesn’t wish to actually save the document?

Thank God for Andre Guirard post after looking further subsequently long enough, (and for Stan Rogers (who if I remember it right, linked to that post somewhere in the same forum,) I came across a code that not only performs what I needed but also works from version 5.0.2 up and doesn’t require the saving of the destination document.

So from the said post:

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 only
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.

Do remember to check the important points there however.

Btw, the image was taken from wikipedia.org.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: