Genii Weblog


Civility in critiquing the ideas of others is no vice. Rudeness in defending your own ideas is no virtue.


Wed 8 Sep 2004, 09:03 AM
As I have written before, there are a number of questions which come up in the forums over and over.  I have written about Hiding a rich text field, for example, and an extremely popular post on Writing better hide-when formulas.  This is a less frequently asked question, but one which shows how Midas can help if other solutions do not.

How do I check whether [fill in the blank] is in my rich text field?
The question is usually something similar to the one I answered today:
Hello Notes Gurus,

How to check whether doclink is existing in a richtext field or not either using Formula or lotusscript @notesclient...

THanks in advance.
  - Ganesh Setty (link)Sometimes, the question is about doclinks, sometimes about images, sometimes about tables, and sometimes about attachments.  The native solutions vary, but I'll try to cover the most common here.

Is there a doclink in this rich text field?
You can often tell that there are doclinks somewhere in some field on the document by seeing if there is a $Links field, but there can be doclinks that don't need $Links (such as those created by native LotusScript or by third party products), and there can sometimes be a $Links even when the rich text does not contain a doclink.  In addition, there can be doclinks in a $FormLinks field when the doclink is contained on a form.

The only real way to be sure is to cycle through the rich text records looking for either a CD_LINK2 record or CD_LINKEXPORT2 record, or for a CDRESOURCE record which has the correct type in it.  Not simple, I'm afraid.  In Notes 6 and above, you can dump the contents of the rich text to XML and search that for the links, but the level of effort isn't that much lower.

Of course, our Midas Rich Text LSX will do this easily.  The code would be very simple:

Call rtitem.ConnectBackend(doc.Handle, "Body", True)
If rtitem.Everything.GetCount("Doclink") > 0 Then
   ' *** The Body field does have doclinks
End If

This would also be easy in formula language with our @Midas Formulas:

count := @DbCommand("Midas":"NoCache"; "GetCount"; ""; @DocumentUniqueID; "Body"; "Doclink");

Is there a graphic/image/picture in this rich text field?
There is no obvious mechanism for detecting images the way there is for doclinks, as the information is contained in the rich text records and not in a separate field.  Thus, the only sure fire way is to cycle through the CD records again, this time looking for CD_GRAPHIC or CD_BITMAPHEADER records.  In Notes 6 and above, you can dump the contents of the rich text to XML and search that for the graphic tags, but the level of effort isn't that much lower.

But, using our Midas Rich Text LSX (with code that looks a lot like that for doclinks):

Call rtitem.ConnectBackend(doc.Handle, "Body", True)
If rtitem.Everything.GetCount("Graphic") > 0 Then
   ' *** The Body field does have images
End If

Or using @Midas Formulas:

count := @DbCommand("Midas":"NoCache"; "GetCount"; ""; @DocumentUniqueID; "Body"; "Graphic");

Is there an attachment in this rich text field?
Both formula language and LotusScript actually do contain ways to find the attachments on a document, and LotusScript also offers the ability to find the attachments in a specific rich text field.  In formula language, the @Attachments formula will return the number of attachments on the whole document.  The native LotusScript classes let you do this for a document, but also for a rich text field, by using the EmbeddedObjects property on the NotesDocument and NotesRichTextItem classes, respectively.

Again, this is also possible using our Midas Rich Text LSX (with code that looks a lot like that for doclinks and images):

Call rtitem.ConnectBackend(doc.Handle, "Body", True)
If rtitem.Everything.GetCount("File") > 0 Then
   ' *** The Body field does have images
End If

Or using @Midas Formulas:

count := @DbCommand("Midas":"NoCache"; "GetCount"; ""; @DocumentUniqueID; "Body"; "File");

Is there a table in this rich text field?
There is no obvious mechanism for detecting tables the way there is for doclinks, as the information is contained in the rich text records and not in a separate field.  Thus, the only sure fire way is to cycle through the CD records again, this time looking for CD_TABLE or CD_NESTEDTABLE records.  In Notes 6 and above, you can dump the contents of the rich text to XML and search that for the table tags, but the level of effort isn't that much lower.

But, using our Midas Rich Text LSX (with code that looks a lot like that for doclinks, images, and file attachments):

Call rtitem.ConnectBackend(doc.Handle, "Body", True)
If rtitem.Everything.GetCount("Table") > 0 Then
   ' *** The Body field does have images
End If

Or using @Midas Formulas:

count := @DbCommand("Midas":"NoCache"; "GetCount"; ""; @DocumentUniqueID; "Body"; "Table");
And so on
For most other rich text constructs, the options are examining the CD records, dumping to XML and searching, or using a product such as the Midas Rich Text LSX or the @Midas Formulas.  Just replace the word "Table" above by "Section" for sections, "Button" for buttons, "Hyperlink" for link hotspots, "URLLink" for URL hotspots, "Layer" for layers, etc. etc.

Copyright © 2004 Genii Software Ltd.