Link to home
Start Free TrialLog in
Avatar of gcousins
gcousinsFlag for Ireland

asked on

Reminder Agent: Getting "Object Variable not set"

I'm developing a training resources database. There is a form and a hidden view called "Courses2". TThe fields, from the form, in the view used are:
Employee_Email
Trainer_Email
TL_Email
HR_Email
Act_Start_Date

All fields are text except for Act_Start_Date which is Date/Time. All are editable.                                                

I've written a scheduled agent that is supposed to run once a day on documents in a view. The agent checks all the documents in the view and checks that the date in Act_Start_Date is 30 days before todays date. If it finds a document it mails the employee and the TL (team leader).

When I run the agent manually I get "Object Variable not set".

My code is

Sub Initialize
      Dim s As New notessession
      Dim db As notesdatabase
      Set db=s.currentdatabase
      Dim due As notesview
      Dim maildoc, viewdoc As notesdocument
      Dim daten As Variant
      Dim duedate As String
      Dim TL As String
      Dim Employee As String
      Set due=db.getview("Courses2")
      Set viewdoc=due.getfirstdocument
      
      Do Until viewdoc Is Nothing
            
            daten=Today()
            duedate=viewdoc.Act_Start_Date(0)
            TL=viewdoc.TL_Email("")
            Employee=viewdoc.Employee_Email(0)
            
            If daten=(duedate-30) Then
                  Set maildoc=db.createdocument
                  maildoc.form="Memo"
                  Dim rtitem As New notesrichtextitem(maildoc, "Body")
                  maildoc.Subject="Training Reminder - 1 month to go"
                  Call maildoc.AppendItemValue("SendTo",TL)
                  Call maildoc.AppendItemValue("CC",Employee)
                  Call rtitem.AppendText( "Training in a month's time for"& Employee)
                  Call maildoc.send(False, maildoc.SendTo(0))
            End If
            
            Set viewdoc=due.getnextdocument(viewdoc)
      Loop
      
End Sub  
SOLUTION
Avatar of HemanthaKumar
HemanthaKumar

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gcousins

ASKER

Hi,

What do you mean by Add Search button?

Gary
I'm now getting an error when I try to save the agent, "Not a member: GETFIRSTDOCUMENTS"
Hi,

Forget the last comment, I've now got a script that looks like this but I've got an error "Wrong number of arguments for: GETFIRSTDOCUMENT".

Sub Initialize
      Dim s As New notessession
      Dim db As notesdatabase
      Set db=s.currentdatabase
      Dim col As NotesDocumentCollection
      Dim doc As NotesDocument
      Dim maildoc, viewdoc As notesdocument
      Dim daten As Variant
      Dim duedate As String
      Dim TL As String
      Dim Employee As String
      Set col = db.UnProcessedDocuments
      Set doc = col.GetFirstDocument(doc)
      While Not doc Is Nothing
            
            daten=Today()
            duedate=viewdoc.Act_Start_Date(0)
            TL=viewdoc.TL_Email(0)
            Employee=viewdoc.Employee_Email(0)
            
            If daten=(duedate-30) Then
                  Set maildoc=db.createdocument
                  maildoc.form="Memo"
                  Dim rtitem As New notesrichtextitem(maildoc, "Body")
                  maildoc.Subject="Training Reminder - 1 month to go"
                  Call maildoc.AppendItemValue("SendTo",TL)
                  Call maildoc.AppendItemValue("CC",Employee)
                  Call rtitem.AppendText( "Training in a month's time for"& Employee)
                  Call maildoc.send(False, maildoc.SendTo(0))
            End If
            
            Set doc = col.GetNextDocument(doc)
      Wend
      
End Sub

Avatar of Sjef Bosman
GetFirstDocument doesn't have parameters.
Avatar of HemanthaKumar
HemanthaKumar

that is a typo

Not >set doc = col.GetFirstDocuments

it should be
set doc = col.GetFirstDocument
Ok, my script now looks like this but when I run it manually I get "object variable not set". Is datedate declared properly as string?

Sub Initialize
      Dim s As New notessession
      Dim db As notesdatabase
      Set db=s.currentdatabase
      Dim col As NotesDocumentCollection
      Dim due As notesview
      Dim doc As NotesDocument
      Dim maildoc, viewdoc As notesdocument
      Dim daten As Variant
      Dim duedate As String
      Dim TL As String
      Dim Employee As String
      Set Due = db.GetView( "Courses2" )
      Set doc = due.GetFirstDocument
      While Not doc Is Nothing
            
            daten=Today()
            duedate=viewdoc.Act_Start_Date(0)
            TL=viewdoc.TL_Email(0)
            Employee=viewdoc.Employee_Email(0)
            
            If daten=(duedate-30) Then
                  Set maildoc=db.createdocument
                  maildoc.form="Memo"
                  Dim rtitem As New notesrichtextitem(maildoc, "Body")
                  maildoc.Subject="Training Reminder - 1 month to go"
                  Call maildoc.AppendItemValue("SendTo",TL)
                  Call maildoc.AppendItemValue("CC",Employee)
                  Call rtitem.AppendText( "Training in a month's time for"& Employee)
                  Call maildoc.send(False, maildoc.SendTo(0))
            End If
            
            Set doc = col.GetNextDocument(doc)
      Wend
      
End Sub

Sorry, I meant Datedue declared properly?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Bossie4 for your help, as you've probably worked out I'm new to Lotusscript. What should I select in the Document Selection part of the agent? I'm also still getting the same error when the agent runs manually.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I ran the debugger as you suggested and got the error at the following line:

Set doc = due.GetFirstDocument
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Good one sjef :-)

G, you should always add 'option declare' (without the quotes) to the options section of all scripts you write.  That will at least not allow you to use variables that were not declared, and will prevent typos (trust me, I know)

In the Document Selection part of your agent, you don't have to put anything, because this agent will have to work on 'All documents in database' (because you use a view to get the documents to work on).

cheers,

Tom
You were right I had named it as [Courses2] but have now changed it to Courses2. The agent now runs but I still get the error message.
You get "the" error message... I don't have "the" answer ;)

Does the agent run manually? Then use the debugger over and over again, until you find the error. And please be a little more descriptive :)
OK guys, how do you want the points? Both sjef and bossie4 provided me with lots of information and Herman contributed at the start. How about 200,200,100?
You want us to fight over the "bones"? Hah!

Sjef ;)
Well if I give all the points to one person the others will feel agrieved. I'll go with the 200,200,100 split.

Nobody will complain if the rules about points are (more or less) obeyed. They're somewhere on EE, but I never seem able to find them. Your split suits me fine. Thanks!
The error in question is "Object variable not set", the line is Set doc = col.GetNextDocument(doc) and col has no value in the variable tab of the debugger.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks sjef, It works. I'll allocate the points. Thanks to all for their time.
Missed that 1 in the code I corrected .... Should have gotten rid of the 'dim col... ' stuff, so it would have shown up quite easily  ....

Tom
One small problem guys, I let the agent run over the weekend and it mails every day. It's supposed to be a reminder to let someone know that if they have training in one months time e,g. if they have training on 20th December it should mail them once to let them know on the 21st November (30 days before). I think what its doing now is 30 days or less.

Ask Tom why he changed this line:
          if daten.lslocaltime > duedate.lslocaltime then
Hi Tom,

Any idea on the above issue?
Maybe Tom is busy. Well, normally it's better to use less/greater than or equal, because a date is easily missed: the server goes down unexpectedly, maintenance during a Sunday, whatever. You could change your agent a little (in pseudo-code):

    If the reminder hasn't been sent already Then
        If within warning period Then
            send reminder
            doc.ReminderSent= Now
        End If
    End If