Solved

Cycling through $Body form fields in LotusScript

Posted on 2004-03-26
13
1,669 Views
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!
0
Comment
Question by:evets27
  • 3
  • 3
  • 3
  • +1
13 Comments
 
LVL 24

Expert Comment

by:HemanthaKumar
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.

~Hemanth
0
 

Author Comment

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

Expert Comment

by:HemanthaKumar
ID: 10689940
Will do.
0
 
LVL 31

Expert Comment

by:qwaletee
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.
0
 

Author Comment

by:evets27
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...
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 31

Expert Comment

by:qwaletee
ID: 10707514
In R5, there is no explicit mechanism for finding design objects.  If you go to the notes.net 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.
0
 
LVL 31

Assisted Solution

by:qwaletee
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.)
0
 

Author Comment

by:evets27
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.
0
 
LVL 24

Accepted Solution

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

Expert Comment

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

http://www-10.lotus.com/ldd/sandbox.nsf/e7425656e0c80508852567540065d7f9/f81067f94a1143f3852567d800660625

Peter
0
 
LVL 5

Assisted Solution

by:pgloor
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


Const MAXTUMBLERLEVELS% = 32

' 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

Type NOTEID
  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

%REM
STATUS LNPUBLIC NIFFindDesignNote(
 DBHANDLE  hFile,
 char far *Name,
 WORD  Class,
 NOTEID far *retNoteID);
%END REM
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 )
  Else
    ' 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

0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
IBM Notes offer Encryption feature using which the user can secure its NSF emails or entire database easily. In this section we will discuss about the process to Encrypt Incoming and Outgoing Mails in depth.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

757 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now