“Object variable not set” error in lotus script

10 pts.
Tags:
Lotus Script
how to resolve the "Object variable not set" error in lotus script?

Software/Hardware used:
software

Answer Wiki

Thanks. We'll let you know when a new response is added.

This error is occurred mainly when object is not set to correct value or value written in the script is not found. for example if we are using following line :

set view=db.getview(“abs”)
set doc=view.getfirstdocument
and  that view “abs” is not existing then the error is generated in the second line.Lotus notes debugger helps to find out such errors.

Discuss This Question: 5  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • Stiletto
    "Object variable not set" is a very common error that can be caused by a wide variety of coding mistakes.  Your best bet to get help here would be to post your code.  It could be a simple typo, or a syntax error.
    5,475 pointsBadges:
    report
  • philipp123hess

    Can someone help on this script?

    It just won't work :-(, would be really appreciated.



    Sub Initialize
     
     Const sForward = "Lorenzo Natale/Home-Office/Zurich"
     
     Dim session As New NotesSession
     Dim note As NotesDocument
     Dim docNew As Notesdocument
     Dim db As NotesDatabase
     Dim item As NotesItem
     
     If note.From(0) = "Philipp Hess/Home-Office/Zurich" Then
      
      
      Set session = New NotesSession
      Set db = session.CurrentDatabase
      Set note = session.DocumentContext
      Set item = note.GetFirstItem("Body")
      
      Set docNew = New Notesdocument(db)
      docNew.Form = "Memo"
      Call item.copyitemtodocument(docNew, "")
      docNew.SendTo = sForward
      docNew.From = " " & note.From(0)
      docNew.Principal = " " & note.From(0)
      docNew.Subject = note.Subject(0)
      
      Call docNew.Send(True)  
      
     End If
     
     If note.Subject(0) = "Test" Then
      
      
      Set session = New NotesSession
      Set db = session.CurrentDatabase
      Set note = session.DocumentContext
      Set item = note.GetFirstItem("Body")
      
      Set docNew = New Notesdocument(db)
      docNew.Form = "Memo"
      Call item.copyitemtodocument(docNew, "")
      docNew.SendTo = sForward
      docNew.From = " " & note.From(0)
      docNew.Principal = " " & note.From(0)
      docNew.Subject = note.Subject(0)
      
      Call docNew.Send(True)  
      
     End If
     
     
    End Sub

    10 pointsBadges:
    report
  • Stiletto
    In your very first IF statement, you refer to note.From(0), but at that point you haven't assigned "note" to anything. As a result, it is undefined.
    5,475 pointsBadges:
    report
  • paulinebgg2500
    Pls help me,

    Im also have the same error which is object variable not set on line 124...and this make the daily agent in lotus script is running unsucsesfully. Here is the code.

    %REM
        Agent Process Time Attendence
        Created Apr 19, 2010 by Kenny Chong Siaw Yoon/Directors/pcs
        Description: Comments for Agent
    %END REM
    Option Public
    Use "Process Time Library"
    'all lotuscript language error codes
    %Include "lserr.lss"
    ' all Notes Backend Class error codes
    %Include "lsxbeerr.lss"


    Sub Initialize()
        On Error GoTo errhandler   
    Print"Agent:Process Time Attendance Only started running at " & DateValue(Now()) & "," + TimeValue(Now())
        Dim ss As New NotesSession
        Dim db As NotesDatabase, ArchiveDB As NotesDatabase
        Dim sysVw As NotesView, SysDoc As NotesDocument
        Dim staffVw As NotesView,staffVc As NotesViewEntryCollection
        Dim staffVe As NotesViewEntry, staffDoc As NotesDocument
        Dim Tdy As Variant
        Dim intl As NotesInternational
        Dim svrtime As string
       
        Set db=ss.Currentdatabase
       
        tdy=DateValue(Now)
        '    default time is 12:30am run
        '    now change to 1.50 pm run
        ' Get Archive database location from system settings
        Set sysvw=db.getview("($System Settings)")
        Set sysdoc=sysvw.Getfirstdocument()
        If sysdoc Is Nothing Then Exit Sub 'cannot run without system settings
        macro$="@Name([Abbreviate];@subset(@dbname;1))"
        svr=Evaluate(macro$)
        '    If UCase(svr(0))<>UCase(sysdoc.ServerPath(0)) Then
        '        Exit Sub                        'must run on Server DB
        '    End If
        Set Archivedb=ss.Getdatabase(sysdoc.ArchivePath(0), sysdoc.ArchiveDB(0), false)   
        '    If Not Archivedb.Isopen Then Exit Sub
       
        '    start printing absent record time
        'Print "Processing absent records start at:" + Now
       
       
        'loop from last run date+1 to today
        Dim dd As Variant, ApprPrd As Integer, MvePrd As Integer
       
        %rem
        Set staffvw=db.Getview("($Active Staff by ID)")
        Set staffVc=staffvw.Allentries
        Set staffve=staffvc.Getfirstentry()
        Do While Not (StaffVe Is Nothing)
            Set staffdoc=staffve.Document
            '****  recalc effective dept
            'Call staffdoc.Computewithform(True,False)
            'Call staffdoc.save(True,False)
            '******************
            dd=sysdoc.AgentLastRun(0)
            If dd="" Then dd=tdy-1
            Do While DateValue(dd)<DateValue(tdy)
                dd=dd+1
    '            Print "Create absent records for staff ID:" & staffdoc.staffID(0) & _
    '                    " " & Format$(dd,"dd/mm/yyyy")           
                Call CreateAbsentRec(Staffdoc, dd)
            Loop
            Set staffve=staffvc.Getnextentry(staffve)
        Loop

        '    Print the abesent record ending times
            Print "Processing absent records end at:" + Now
        %end rem

        'Check Duplicate and save conflict
        Call GetDuplDoc()

        ' check if any of the movement database doesn't have the 2 views
        ' for HLAS enhancement
        ' if any of the movement database doesn't have either 1 or both
        ' of the views, copy it from the CICTS database
        Dim mvagt As NotesAgent
        Set mvagt = db.Getagent("(Check MVDB Without HLAS Views)")
        Call mvagt.Runonserver()

        'Process all time records
        ApprPrd=CInt(sysdoc.HodAlertRepetition(0))
        MvePrd=CInt(sysdoc.MatchPrd(0))
        Dim timeVw As NotesView, timedoc As NotesDocument
        Dim timeVc As NotesViewEntryCollection, timeVe As NotesViewEntry
       
       
        '    Start processing Time record time :

        Print "Processing time records start : " + Now
       
       
        Set timeVw=db.getview("(Time Attendance Maintenance By StaffID & Date)")
        Set timeVc=timeVw.Allentries
        Set tobeDeleted=timeVw.Getalldocumentsbykey("", true)
        Call tobeDeleted.removeall(True)
        Set timeVe=timeVc.Getfirstentry()
        Do While Not (timeVe Is Nothing)
            Set Timedoc=timeVe.Document
            ky$=timedoc.TStaffID(0)+Format$(Timedoc.TDate(0), "dd/mm/yyyy")       
            '    Print "Processing time records: " & timedoc.TstaffID(0) & " Date: " & _
            '            Format$(timedoc.Tdate(0),"dd/mm/yyyy")
            tdte=DateValue(timedoc.Tdate(0))
            If Not IsDate(timedoc.cutoff(0)) Then
                Cutoff=TimeValue("12:00AM")        '(CDat(""))
                Print "Warning! Invalid Cutoff time for Staff ID "  & timedoc.TStaffID(0) & _
                " on " & Format$(timedoc.tdate(0), "dd/mm/yyyy")
            Else
                Cutoff=TimeValue(timedoc.cutoff(0))           
            End If
            If tdte< Today-1 Or (tdte=Today-1 And TimeValue(Now)>=cutoff) Then
                Call uiProcessTime(timedoc, True)
                IsLate=True
                If IsNull(ArrayGetIndex(timedoc.TDetail,"Late-In")) Then IsLate=False
                IsMv=True
                If IsNull(ArrayGetIndex(timedoc.TDetail,"Movement")) Then IsMv=False
                Dim ExcludeHoliday As Boolean, ExcludeOffday As Boolean, IncludeHoliday As Boolean, IncludeOffday As Boolean
                IncludeHoliday=True
                ExcludeHoliday=False
                IncludeOffday=True
                ExcludeOffday=false
                ldte=DateValue(AdjustedDate(timedoc.TstaffID(0), tdte, ApprPrd, ExcludeOffday, ExcludeHoliday))
                mdte=DateValue(AdjustedDate(timedoc.TstaffID(0), tdte, MvePrd, ExcludeOffday, ExcludeHoliday))
                If timedoc.TStatus(0)<>"Incomplete" And _
                ((Not IsLate And Not IsMv)Or _
                (IsLate And (timedoc.Approved(0)<>"" Or Now>=ldte+cutoff)) Or _
                (IsMv And Now>=mdte+cutoff)) _
                Then timedoc.AlreadyProcessed="Y"
                Call timedoc.save(True,False)
            End If
    nextstaff:
            Set timeve=timeVc.Getnextentry(timeVe)
        Loop
       
        '    Print the ending for processing times record
        Print "Processing time records end : " + Now
       
        'update date of last run
        sysdoc.AgentLastRun=tdy
        Call sysdoc.save(True,False)
        Dim agt As NotesAgent
        Set agt=db.getagent("(Archive Processed Attendance)")
        Call agt.Runonserver()
        'Print "Processing completed"
    Print"Agent:Process Time Attendance Only ended running at " & DateValue(Now()) & "," + TimeValue(Now())
        Exit Sub
    ErrHandler:
        Print "Got error " & Error$ & " on line " & CStr(Erl)
        If Not timedoc Is Nothing Then
            Print timedoc.Department(0) + " - " + timedoc.TStaffID(0) + " - "+ timedoc.TStaffName(0) + " - " + Format$(timedoc.TDate(0), "dd/mm/yyyy")
        End If
        Resume nextstaff
    End Sub

    Sub Terminate()
       
    End Sub



    %REM
        Sub GetDuplDoc
        Description: Comments for Sub
    %END REM
    Sub GetDuplDoc
        Dim tvw As NotesView, tVc As NotesViewEntryCollection
        Dim tdoc As NotesDocument
       
        Set tVw=db.getview("(Time Attendance Maintenance By StaffID & Date)")
        Set tVc=tVw.Allentries
        Set tobeDeleted=tVw.Getalldocumentsbykey("", True)
        Call tobeDeleted.removeall(True)
       
        PrvKy$=""
        Cnt%=0
        Set tVe=tVc.Getfirstentry()
        Do While Not (tVe Is Nothing)
            Set tdoc=tVe.Document
            ky$=tdoc.TStaffID(0)+Format$(tdoc.TDate(0), "dd/mm/yyyy")
            If ky$<>prvKy$ Then
                If PrvKy$<>"" And Cnt%>1 Then
                    'get the document to save and repl fields with the merged data
                    GrpTimes=FullTrim(Grptimes)
                    GrpClock=FullTrim(GrpClock)
                    GrpLoc=FullTrim(GrpLoc)
                    If Not IsDate(tdoc.cutoff(0)) Then
                        Call tdoc.Replaceitemvalue("cutoff", TimeNumber(6,0,0))
                    End If
                    Selecteddoc.TAmend=ArrayUnique(FullTrim(sortTimes(GrpTimes, tdoc.cutoff(0))))
                    Selecteddoc.TClock=ArrayUnique(GrpClock)
                    Selecteddoc.TClockCode=GrpLoc
                    Selecteddoc.LateReason=LateinR$
                    Selecteddoc.Approver=Appr$
                    Selecteddoc.TRemarks=rmk$
                    Selecteddoc.DTApproved=DTAppr
                    Selecteddoc.DTSubmit=DTSmt
                    Call SelectedDoc.save(True, False)
                End If
                GrpTimes=tdoc.TAmend
                GrpClock=tdoc.TClock
                GrpLoc=tdoc.TClockCode
                lateinR$=tdoc.LateReason(0)
                Appr$=tdoc.Approver(0)
                rmk$=tdoc.TRemarks(0)
                DtAppr=tdoc.DTApproved(0)
                DTSmt=tdoc.DTSubmit(0)
                PrvKy$=ky$
                Cnt%=0
                Set selectedDoc=nothing
            End If
            If tdoc.parentdocumentunid()="" And selectedDoc Is Nothing Then
                Set selectedDoc=tDoc
            Else
                Call tobeDeleted.Adddocument(tDoc)                       
            End If
           
            idx%=0
            ForAll tme In tdoc.Tamend
                If IsNull(ArrayGetIndex(GrpTimes, tme))Then
                    GrpTimes=ArrayAppend(GrpTimes, tme)
                    If UBound(tdoc.Tclock)>=idx% Then
                        GrpClock=ArrayAppend(GrpClock, tdoc.TClock(idx%))
                    End If
                    If UBound(tdoc.Tclockcode)>=idx% Then
                        GrpLoc=ArrayAppend(GrpLoc, tdoc.TClockCode(idx%))
                    End If
                end If
                idx%=idx%+1
            End ForAll
            If LateinR$="" Then LateinR$=tdoc.LateReason(0)
            If Rmk$="" Then Rmk$=tdoc.Tremarks(0)
            If Appr$="" Then Appr$=tdoc.Approver(0)
            If Not IsDate(DtAppr) Then DtAppr=tdoc.DTApproved(0)
            If Not IsDate(DTSmt) Then DTSmt=tdoc.DTSubmit(0)
            cnt%=cnt%+1
            Set tVe=tVc.getnextentry(tVe)
        loop
        If Cnt%>1 Then
            'get the document to save and repl fields with the merged data
            GrpTimes=FullTrim(Grptimes)
            GrpClock=FullTrim(GrpClock)
            GrpLoc=FullTrim(GrpLoc)
            If Not IsDate(tdoc.cutoff(0)) Then
                Call tdoc.Replaceitemvalue("cutoff", TimeNumber(6,0,0))
            End If
            Selecteddoc.TAmend=ArrayUnique(FullTrim(sortTimes(GrpTimes, tdoc.cutoff(0))))
            Selecteddoc.TClock=ArrayUnique(GrpClock)
            Selecteddoc.TClockCode=GrpLoc
            Selecteddoc.LateReason=LateinR$
            Selecteddoc.Approver=Appr$
            Selecteddoc.TRemarks=rmk$
            Selecteddoc.DTApproved=DTAppr
            Selecteddoc.DTSubmit=DTSmt
            Call SelectedDoc.save(True, False)
        End If
        Call tobeDeleted.removeall(True)
    End Sub
    55 pointsBadges:
    report
  • Stiletto
    If you're going to drop a couple hundred lines of your code and ask someone to debug it for you, you could at least tell us which line is "line 124". Have you tried stepping through the code with the debugger turned on?
    5,475 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: