?
Solved

Cycling through $Body form fields in LotusScript

Posted on 2004-03-26
13
Medium Priority
?
1,746 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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
 
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 264 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 272 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 264 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

For users on the Lotus Notes 8 Standard client, this article provides information on checking the Java Heap size and adjusting it to half of your system RAM in attempt to get the Lotus Notes 8.x Standard client to run faster.  I've had to exercise t…
This is an old article, please see an updated version of this article, located here: http://www.experts-exchange.com/articles/23619/Notes-8-5x-Windows-7-Notes-info-and-tips.html
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

752 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