gcousins
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.getfirstdocume nt
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("S endTo",TL)
Call maildoc.AppendItemValue("C C",Employe e)
Call rtitem.AppendText( "Training in a month's time for"& Employee)
Call maildoc.send(False, maildoc.SendTo(0))
End If
Set viewdoc=due.getnextdocumen t(viewdoc)
Loop
End Sub
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.getfirstdocume
Do Until viewdoc Is Nothing
daten=Today()
duedate=viewdoc.Act_Start_
TL=viewdoc.TL_Email("")
Employee=viewdoc.Employee_
If daten=(duedate-30) Then
Set maildoc=db.createdocument
maildoc.form="Memo"
Dim rtitem As New notesrichtextitem(maildoc,
maildoc.Subject="Training Reminder - 1 month to go"
Call maildoc.AppendItemValue("S
Call maildoc.AppendItemValue("C
Call rtitem.AppendText( "Training in a month's time for"& Employee)
Call maildoc.send(False, maildoc.SendTo(0))
End If
Set viewdoc=due.getnextdocumen
Loop
End Sub
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I'm now getting an error when I try to save the agent, "Not a member: GETFIRSTDOCUMENTS"
ASKER
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("S endTo",TL)
Call maildoc.AppendItemValue("C C",Employe e)
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
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_
TL=viewdoc.TL_Email(0)
Employee=viewdoc.Employee_
If daten=(duedate-30) Then
Set maildoc=db.createdocument
maildoc.form="Memo"
Dim rtitem As New notesrichtextitem(maildoc,
maildoc.Subject="Training Reminder - 1 month to go"
Call maildoc.AppendItemValue("S
Call maildoc.AppendItemValue("C
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
GetFirstDocument doesn't have parameters.
that is a typo
Not >set doc = col.GetFirstDocuments
it should be
set doc = col.GetFirstDocument
Not >set doc = col.GetFirstDocuments
it should be
set doc = col.GetFirstDocument
ASKER
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("S endTo",TL)
Call maildoc.AppendItemValue("C C",Employe e)
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
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_
TL=viewdoc.TL_Email(0)
Employee=viewdoc.Employee_
If daten=(duedate-30) Then
Set maildoc=db.createdocument
maildoc.form="Memo"
Dim rtitem As New notesrichtextitem(maildoc,
maildoc.Subject="Training Reminder - 1 month to go"
Call maildoc.AppendItemValue("S
Call maildoc.AppendItemValue("C
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
ASKER
Sorry, I meant Datedue declared properly?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I ran the debugger as you suggested and got the error at the following line:
Set doc = due.GetFirstDocument
Set doc = due.GetFirstDocument
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
ASKER
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 :)
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 :)
ASKER
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 ;)
Sjef ;)
ASKER
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!
ASKER
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
Tom
ASKER
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
if daten.lslocaltime > duedate.lslocaltime then
ASKER
Hi Tom,
Any idea on the above issue?
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
If the reminder hasn't been sent already Then
If within warning period Then
send reminder
doc.ReminderSent= Now
End If
End If
ASKER
What do you mean by Add Search button?
Gary