1
votes

I am new to lotus script, and I'm trying to get data from a view and save it into a string. But each time I do that I get the error that Initialize Object variable not set on line 36. In my domino designer Line 36 is right under ItemNames(6).

I tried to use the code from my friend and I get the same error, while his works without a problem.

Please help I'm desperate to make this work.

Sub Initialize

    On Error GoTo ERRSUB

    Dim nSession As New NotesSession
    Dim nDb As NotesDatabase
    Dim nDoc As NotesDocument
    Dim view As NotesView
    Dim nitem As NotesItem

    Dim strRecord As String
    Dim DataString As String
    Dim nList List As String
    Dim ListCount As Integer
    Dim FirstLine As String 
    Dim counter As Integer
    counter = 0

    Dim ItemNames(6) As String  
    ItemNames(0) = "Date"
    ItemNames(1) = "Name"
    ItemNames(2) = "Name of buyer"
    ItemNames(3) = "Naziv of project"
    ItemNames(4) = "value"
    ItemNames(5) = "source"
    ItemNames(6) = "status" 

    Set nDb = nSession.Currentdatabase
    Set view = nDb.Getview("X_view_1")
    Set ndoc = view.Getfirstdocument()

    Do Until (ndoc Is nothing)

        ForAll item In ItemNames
            Set nitem = ndoc.Getfirstitem(item)
            DataString = nitem.Values & ";"
            counter = counter + 1
        End ForAll

        DataString = DataString & Chr(13)

        Set ndoc = view.Getnextdocument(ndoc)
    Loop    

    GoTo DONE

    DONE:   

    MessageBox counter
    Exit Sub    

    ERRSUB:

    Call logger("Error",nSession.currentagent.name,"Initialize","","")
    GoTo done       

End Sub
2
My guess is that it is a categorised view and the first item is just a category with no document items?Dave45
Item Names CANNOT contain spaces so that might be your issue.Newbs

2 Answers

3
votes

Line 36 is DataString = nitem.Values & ";". The error is that nitem is not set properly. Probably the item is not available in a certain document. Test for nitem isn't Nothing.

Change your ForAll loop to

    ForAll item In ItemNames
        Set nitem = ndoc.Getfirstitem(item)
        If Not nitem Is Nothing then
            DataString = DataString & nitem.Text
        End If 
        DataString = DataString & ";"
        counter = counter + 1
    End ForAll
0
votes

I would writ it something like this below.

Among the things I notice in your code: * You use GoTo in your error handler, should be a Resume instead. * You have "GoTo DONE" when the code would get there anyway, that is not needed. * You have several variables declared that you don't use. * You don't use much error checking, Knut's suggestion is a good one.

Here is my suggestion, this is how I would export a view:

Sub Initialize
    Dim session As New NotesSession
    Dim db As NotesDatabase
    Dim view As NotesView
    Dim col As NotesViewEntryCollection
    Dim entry As NotesViewEntry
    Dim DataString As String
    Dim cnt List As Long

    On Error GoTo errHandler
    Set db = session.Currentdatabase
    Set view = db.Getview("X_view_1")
    Set col = view.AllEntries
    '*** Set counters
    cnt("total") = col.Count
    cnt("processed") = 0
    '*** Loop though all view entries, much faster that documents
    Set entry = col.GetFirstEntry()
    Do Until entry Is Nothing
        '*** Update status bar every 100 documents
        If cnt("processed") Mod 100 = 0 Then 
            Print "Processed " & cnt("processed") & " of " & cnt("total") & " documents."
        End If
        '*** Read view columns and add to string
        ForAll cv In entry.ColumnValues
            DataString = cv & ";"
        End ForAll
        '*** Add line break to string
        DataString = DataString & Chr(13)
        '*** Update counter and get next entry in view collection
        cnt("processed") = cnt("processed") + 1
        Set entry = col.GetNextEntry(entry)
    Loop    

exitSub: 
    MsgBox "Processed " & cnt("processed") & " of " & cnt("total") & " documents.",,"Finished" 
    Exit Sub    

errHandler:
    Call logger("Error",session.CurrentAgent.Name,"Initialize","","")
    Resume exitSub       
End Sub

Another way to do it would be to read the the value directly from the NotesDocument:

DataString = doc.GetItemValue(item)(0) & ";"

Of course, this will only read the first value of any multi-value fields, but you can fix that like this:

DataString = Join(doc.GetItemValue(item),"~") & ";"

This will put a ~ between each value if there are more than one, then you can process that the way you like.