Lotus Script Agent Fails

I am running the following code from an agent (web client) and am getting PAGE NOT FOUND error:

Option Public

Dim db As NotesDatabase
Dim maildoc As NotesDocument
Dim subject As String
Dim linkmsg As String
Dim newexist As String
Dim projinfo As String
Dim recipients As Variant

Sub Initialize
      Set db = s.CurrentDatabase
      Set maildoc = db.CreateDocument
      Set bodyitem = maildoc.CreateRichTextItem("Body")
      maildoc.Form = "Memo"
      If Source.IsNewDoc Then
            newexist = "New Project - "
      Else
            newexist = "Project Info Modified - "
      End If
      projinfo = doc.GetItemValue("ProjName")
      recipients = "Michael Rothschild"
      subject = newexist & projinfo
      maildoc.Subject = Subject
      Call bodyitem.AppendDocLink(linkdoc)
      maildoc.SendTo = recipients
      Call maildoc.Send(False)
End Sub
paynestreetAsked:
Who is Participating?
 
p_parthaCommented:
try
if source.isnewnote then

Partha
0
 
p_parthaCommented:
it may not be due to agent alone may be it's b ecoz of the $$return.

I hope this is a webquerysave agent, just try this in the agent

Sub Initialize
on error goto par
     Set db = s.CurrentDatabase
     Set maildoc = db.CreateDocument
     Set bodyitem = maildoc.CreateRichTextItem("Body")
     maildoc.Form = "Memo"
     If Source.IsNewDoc Then
          newexist = "New Project - "
     Else
          newexist = "Project Info Modified - "
     End If
     projinfo = doc.GetItemValue("ProjName")
     recipients = "Michael Rothschild"
     subject = newexist & projinfo
     maildoc.Subject = Subject
     Call bodyitem.AppendDocLink(linkdoc)
     maildoc.SendTo = recipients
     Call maildoc.Send(False)
exit sub
par:
Print "Error Occured on line number" & erl & " Error is " & error
exit sub
End Sub
0
 
paynestreetAuthor Commented:
The results are the same.
It seems as though you took out the Dims and aded an exit sub.
i do have a value in $$Return. Should I remove it?
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
marilyngCommented:
Try instantiating the s object

Dim s as new NotesSession
0
 
p_parthaCommented:
as marilyng said Session shd be declared, if you had not declared, my error routine wud have told you exactly wehre the error is, so i presume that is declared. Try removing the $$return and see whether it works.

Partha
0
 
paynestreetAuthor Commented:
maryling,

Same result.
Is there any way to debug an agent?
Does this code have to run in an agent?
0
 
paynestreetAuthor Commented:
Partha.

Removing the $$Return didn't help.
I really don't know how far I'm getting- or if I'm even getting to the agent.
0
 
p_parthaCommented:
Go to your internet explorer, Go to tools --> internet options , go to the advanced tab(last tab), uncheck show friendly http error messages and then refresh the page which is throwing page cannot be found error

Partha
0
 
paynestreetAuthor Commented:
I got:

Error 404
HTTP Web Server: Lotus Notes Exception - Entry not found in index
0
 
p_parthaCommented:
Most probably there is a dblookup that is failing in the page use @iserrro
or
Sometimes it's possible that you find this kind of error when you use a webquerysave agent and within it you use some wrong field name or view name. So, the solution, in this case, is to try to remove the agent to the webquerysave event and verify that the form has been proceeded. If it so, the problem is in your Lotus agent.

CHeck whether your agent is spelled correctly.
0
 
marilyngCommented:
Call bodyitem.AppendDocLink(linkdoc)  < where is linkdoc defined?

As far as debugging agent, you can either put print statements that will appear in the log.nsf, or run agentlog to send you an email of everything, and log action everywhere.

Also, set Option Declare in the options to make sure you have everything declared.

Entry not found in index.. linkdoc can't be found, I think, or you have some link defined where it cannot be found in the default view index.


0
 
paynestreetAuthor Commented:
Are you saying just to put the code in the WebQuerySave event?
I thought I had to use an agent.
0
 
paynestreetAuthor Commented:
partha,

You were correct. I had forgotten to remove the <> from around the agent name, so that's why I wasn't executing.

Maryling,

I just want to point to the doc that is being saved. WHat is the correct reference?

doc or _doc ?
0
 
paynestreetAuthor Commented:
Now htat I'm getting to the code, Partha's error routine is showing me:

"Error Occured on line number15 Error is Variant does not contain an object"

Here is my code:

Sub Initialize
      On Error Goto par
      Dim s As New NotesSession
      Dim db As NotesDatabase
      Dim maildoc As NotesDocument
      Dim subject As String
      Dim linkmsg As String
      Dim newexist As String
      Dim projinfo As String
      Dim recipients As String
      Set db = s.CurrentDatabase
      Set maildoc = db.CreateDocument
      Set bodyitem = maildoc.CreateRichTextItem("Body")
      maildoc.Form = "Memo"
      If Source.IsNewDoc Then
            newexist = "New Project - "
      Else
            newexist = "Project Info Modified - "
      End If
      projinfo = doc.GetItemValue("ProjName")
      recipients = "Michael Rothschild"
      subject = newexist & projinfo
      maildoc.Subject = Subject
REM Call bodyitem.AppendDocLink(linkdoc)
      maildoc.SendTo = recipients
      Call maildoc.Send(False)
                Exit Sub
           par:
      Print "Error Occured on line number" & Erl & " Error is " & Error
      Exit Sub
End Sub
0
 
p_parthaCommented:
Source is not defined...

try like this

Set source = s.documentcontext on top of this if condition:
If Source.IsNewDoc Then
0
 
paynestreetAuthor Commented:
I'm now getting type mismatch.
.
.
Dim s As New NotesSession
Dim db As NotesDatabase
Dim source As NotesDocument
.
.
.
Set db = s.CurrentDatabase
Set source = s.DocumentContext
If source.IsNewDoc Then
newexist = "New Project - "
Else
newexist = "Project Info Modified - "
End If
0
 
p_parthaCommented:
Please tell us  which line you are getting the error..

Partha
0
 
paynestreetAuthor Commented:
If source.IsNewDoc Then
0
 
paynestreetAuthor Commented:
IsNewNote worked!
What is the rule?
0
 
marilyngCommented:
isnewnote is a property of NotesUIdocument, isnewdoc is property of NotesDocument

Glad you got it to work... sorry, been on a project so time is limited to night, these days.  Glad p_Partha was around to assist.
0
 
p_parthaCommented:
Marilyng
I believe isnewnote is for notesdocument, not for notesuidocument...

Partha
0
 
marilyngCommented:
Yup, got it backwards.. that's what the F1 button is for!! :)  Never trust my memory anymore... #$%#$% growing old(er)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.