Cycling through $Body form fields in LotusScript

Posted on 2004-03-26
Last Modified: 2013-12-18
Hey All;
I'm a fairly advanced VB/VBA coder trying to write LotusScript to cycle through all the forms within a NSF database and read through each one's $Body field (or fields if there's more than one) to look for specific strings.  I've tried several different methods such as doc.FieldGetText( "$Body" ), but I only get errors like "Type Mismatch".  The online help file says "A Field object has no properties or methods" such as Field.Value; how can I read this value in code?

Thanks very much in advance!
Question by:evets27
  • 3
  • 3
  • 3
  • +1
LVL 24

Expert Comment

ID: 10689718
$Body is a richtext field and it sometimes could have been signed .

Treat it as richtext and use GetFormattedText method to extract text values.


Author Comment

ID: 10689730
Just to clarify too; I'm working with R5 not R6
LVL 24

Expert Comment

ID: 10689940
Will do.
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

LVL 31

Expert Comment

ID: 10690124
Echoing Hemantha... but you also need to use a different object type.  Since you are using FieldGetText, you must be using a NotesUiDocument object, which is merely the "front end" -- an on-screen document DISPLAYED USING the form, not the form's design itself.  You want the form itself, which in R5, you can only treat as a NotesDocument and "go hunting" for it.  Otherwise, you have to resort to the C-level API.

Author Comment

ID: 10703855
Thanks for the input guys; I see I have a little to learn about Lotus!  I'm not sure what you mean exactly by 'going hunting'; are there specific functions I can use to do this?  For what I'm looking at I don't think I can invest the time in working with a C-level API; there really isn't an easy way, with the Lotus object model, to loop through and read these values??  When I view the Design Properties for the form it's all right there.  As far as 'front end' vs. back end, I don't really care HOW I get the results, as long as I can read through the $Body text and work with it in code.

Thanks again for responding!  Sorry if I'm being difficult here...
LVL 31

Expert Comment

ID: 10707514
In R5, there is no explicit mechanism for finding design objects.  If you go to the Sandbox, there is a tool called DBDesign that uses LotusScript to declare the external DLL functions for finding the deign elements.  Using VB, you could do the same.

Once you have the BACK END (NotesDocument) object, you can retrieve the NotesRichTextItem named $Body from it using NotesDocument.getFirstItem.  You can then get the text of the rich text $Body field via getFormattedText or via .Text.  Don't expect to be able to make changes to it, though.
LVL 31

Assisted Solution

qwaletee earned 66 total points
ID: 10707542
Note: all "duplicate" $Body fields are treated as if they are a single field in LotusScript.  In early versions of the object model, one used .getFirstItem and .getNextItem to cycle theough them.  As of, I think, R4.11, .getNextItem was deprecated to always return Nothing, and the NotesItem object was changed to that for rich text items, multiple items are treated as one.  (Unfortunately, it is possible for other types to have duplicate items, and there is no easy way to get to them.)

Author Comment

ID: 10713785
Sorry to be high-maintenance about this (I'll raise the point value of this question); but all of the documentation I'm seeing says "'...set value of doc..." without giving good examples of how to do it.  I've tried looping through the Forms collection using "Forall form In db.Forms" and that works all right; then I loop through the Fields collection to get the names of the fields.  But I can't get the values from there.  Can I get to the $Body value via the Forms collection or will I have to open it as a NotesDocument, then use getFirstItem > getFormattedText?  And I won't need to make form changes, just browsing through so if $Body is read-only that's no problem.
LVL 24

Accepted Solution

HemanthaKumar earned 68 total points
ID: 10714421
Treat it as NotesDocument.. NotesForm will hide internal fields

Expert Comment

ID: 10717666
If you have access to a Notes Designer, than this DB might be of help for you:


Assisted Solution

pgloor earned 66 total points
ID: 10723775
The following LotusScript code basically does what you want.  It uses some API calls which are required to get access to the design note.

I cannot provide a VB example because due to a system crash (don't worry, not related to this code) I have currently no access to it.

' DesignFormProcessing:

Option Public
Option Declare ' Use Option Explicit in VB


' In this example only NOTE_CLASS_FORM will be needed
Const NOTE_CLASS_FORM% = &H0004  '*** form note
Const NOTE_CLASS_VIEW% = &H0008  '*** view note
Const NOTE_CLASS_FILTER% = &H0200  '*** filter note
Const NOTE_CLASS_FIELD% = &H0400  '*** field note
Const NOTE_CLASS_REPLFORMULA% = &H0800  '*** replication formula
Const NOTE_CLASS_ALL% = &H7FFF '*** all note types

  nid As Long             ' typedef DWORD NOTEID;
End Type

Declare Function W32_NSFDbOpen Lib "nnotes.dll" Alias "NSFDbOpen" _
( Byval dbName As String, hdb As Long ) As Integer
Declare Function W32_NSFDbClose Lib "nnotes.dll" Alias "NSFDbClose" _
( Byval hdb As Long ) As Integer

 char far *Name,
 WORD  Class,
 NOTEID far *retNoteID);
Declare Function W32_NIFFindDesignNote _
Lib "nnotes.dll" _
Alias "NIFFindDesignNote" ( _
Byval hdb As Long, _
Byval deName As String, _
Byval declass As Integer, _
retNoteID As NOTEID ) As Integer

Sub Initialize
  ' Notes Objects
  Dim session As New NotesSession
  Dim db As NotesDatabase
  Dim dc As NotesDocumentCollection
  Dim doc As NotesDocument
  Dim note As NotesDocument
  Dim rtItem As NotesRichTextItem
  ' API related variables
  Dim hDb As Long
  Dim rc As Long
  Dim nid As NOTEID
  ' Open the database and get its API handle
  Set db = session.CurrentDatabase
  ' Check if there are any forms in this database
  If Isempty(db.Forms) Then
    Print "No Forms available"
    Exit Sub
  End If
  ' Get an API handle to the database
  If db.Server = "" Then
    ' No Server specified, just use filepath
    rc = W32_NSFDbOpen( db.Filepath, hDb )
    ' Open database on specified server using
    ' a netpath construct (db!!filepath)
    rc = W32_NSFDbOpen( db.server & "!!" & db.Filepath, hDb )
  End If
  ' Check the return code
  If rc <> 0 Then
    ' Return code must be zero, otherwise an error occurred
    Print "Couldn't open db  [" & Cstr(rc) & "]"
    rc = W32_NSFDbClose( hDb )
    Exit Sub
  End If
  ' Iterate thru the list of forms and get each forms design note
  Forall forms In db.Forms
    ' Get the form design note using the form name
    rc = W32_NIFFindDesignNote( hDb, forms.Name, NOTE_CLASS_FORM%, nid )
    ' Check for API errors
    If rc <> 0 Then
      ' Return code must be zero, otherwise an error occurred
      Print "Couldn't get design note [" & Cstr(rc) & "]"
      rc = W32_NSFDbClose( hDb )
      Exit Sub
    End If
    ' Get the design note as a notes document for
    ' further processing with LotusScript
    Set note = db.GetDocumentById(Hex(nid.nid))
    ' Always make sure a document has been returned
    If Not note Is Nothing Then
      ' Get the $Body item
      Set rtItem = note.GetFirstItem("$Body")
      ' Process the body item here
      Print rtItem.GetFormattedText( True, 0)
    End If
  End Forall  
  ' Close the database (API)
  rc = W32_NSFDbClose( hDb )
End Sub


Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Encrypted Mail message in a NSF 10 30
Username format for Domino LDAP 3 91
Add code to Lotus Notes view column 2 123
IBM Lotus Notes Rules not working 5 165
For Desktop Techs: How to retain a user's Notes configuration data when swapping out the end user's computer. (Assuming that you are not upgrading to a completely different version of Notes client) All you need to do is: 1) install Notes o…
Notes Document Link used by IBM Notes is a link file which aids in the sharing of links to documents in email and webpages. The posts describe the importance and steps to create a Lotus Notes NDL file in brief.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question