0
votes

I have database within Lotus Notes and I trying to write a LotusScript that will loop through all of the forms until a specified form name is selected. Once the specified form name is selected execute the rest of the code.

Basically, I am trying to do a

Forall  Form  In db.Forms
 For form.name <> "Server Information"
    Next form
(loop until "Server Information)
 ...... (rest of code)

End Forall

Below is the full code I am working with.

Sub Initialize

    Dim session As New NotesSession
    Dim db As NotesDatabase
    Dim fileName As String
    Dim fileNum As Integer
    Dim headerstring As String
    Dim values As String
    Dim selection As String
    Dim collection As NotesDocumentCollection
    Dim doc As notesdocument
    Dim exportField List As String

    On Error Resume Next

    exportField("ServerName_5") = "ServerName_5"

    Set db = session.CurrentDatabase


    Forall  Form  In db.Forms
        'I WANT TO SKIP ALL FORM NAMES UNTIL "Server Information" is the current or selected form
        'Once the entire loop is complete I don't to go to the next form
        If Isempty(form.Fields) Then
            Messagebox form.Name & " has no fields"
        Else
            If form.Name = "Server Information" Then            
                fieldCount = 0
                msgString = ""
                fileNum% = Freefile()
                fileName$ = "c:\temp\" & form.Name & ".csv"
                Open FileName$ For Output As fileNum%

                Forall field In form.Fields
                    If Iselement(exportField(field)) Then                   
                        msgString = msgString & Chr(10) & _
                        "" & field
                        fieldCount = fieldCount + 1  
                        headerstring=headerstring & |"| &field &|",| 
                    End If
                End Forall

                Write #fileNum%,  |",| & headerstring & |"|
                headerstring=""
            Else
            End If



        End If



        selection = |Form="| & form.Name & |"|
        Set collection=db.Search(selection, Nothing, 0)

        For x = 1 To collection.count
            Set doc =collection.GetNthDocument(x)
            values=""
            Forall formfield In form.Fields
                If Iselement(exportField(formfield)) Then
                    newvalue=doc.GetItemValue(formfield)
                    values=values & |"| & Cstr(newvalue(0)) & |",| 
                End If   
            End Forall

            Write #fileNum%,  |",| & values &|"|
            values=""
        Next

'now check aliases
        If Isempty(form.Aliases) Then
'Messagebox form.Name & " has no aliases"
        Else
            Forall aliaz In form.Aliases
                If aliaz = form.Name Then
                    Goto NextAliaz   'alias is same as form name
                End If
                selection = |Form="| & aliaz & |"|  
                Set collection=db.Search(selection, Nothing, 0)

                For x = 1 To collection.count
                    Set doc =collection.GetNthDocument(x)
                    values=""
                    Forall formfield In form.Fields
                        If Iselement(exportField(formfield)) Then
                            newvalue=doc.GetItemValue(formfield)
                            values=values & |"| & Cstr(newvalue(0)) & |",| 
                        End If   
                    End Forall

                    Write #fileNum%,  |",| & values &|"|
                    values=""
NextAliaz:
                Next
            End Forall
        End If

        Close fileNum%
    End Forall

End Sub
1
What exactly is it you're trying to do? Write the form fields as a header row and then export documents with the Server Information form to a CSV? Only write the ServerName_5 field from those documents to the file? Is the whole "isElement()" thing testing to see if the document has that field?Duston
What is your question? What happens when you run your code? And what doesn't happen that you expect to happen. Please be specific.Richard Schwartz

1 Answers

1
votes

First, I'll teach you how to fish.

A faster and easier fishing technique as long as you remain in the realm of classic Notes developpement : Help\help85_designer.nsf (get it from IBM's website or from here if you are in version 9)

Then, here is your fish for today.

do
   (...stuff...)
until (the condition you want)

Note however that this carries the classic risk of the dreaded infinite loop, as the desired condition may of may not ever be reached.

You may prefer to use the getForm() method of the NotesDatabase class. Don't underestimate the power and expressiveness the the object oriented features of LotusScript and the ready-made, built-in classes of the Domino API.