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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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?
marilyngCommented:
Try instantiating the s object

Dim s as new NotesSession
Starting with Angular 5

Learn the essential features and functions of the popular JavaScript framework for building mobile, desktop and web applications.

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
paynestreetAuthor Commented:
maryling,

Same result.
Is there any way to debug an agent?
Does this code have to run in an agent?
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.
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
paynestreetAuthor Commented:
I got:

Error 404
HTTP Web Server: Lotus Notes Exception - Entry not found in index
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.
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.


paynestreetAuthor Commented:
Are you saying just to put the code in the WebQuerySave event?
I thought I had to use an agent.
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 ?
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
p_parthaCommented:
Source is not defined...

try like this

Set source = s.documentcontext on top of this if condition:
If Source.IsNewDoc Then
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
p_parthaCommented:
Please tell us  which line you are getting the error..

Partha
paynestreetAuthor Commented:
If source.IsNewDoc Then
p_parthaCommented:
try
if source.isnewnote then

Partha

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
paynestreetAuthor Commented:
IsNewNote worked!
What is the rule?
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.
p_parthaCommented:
Marilyng
I believe isnewnote is for notesdocument, not for notesuidocument...

Partha
marilyngCommented:
Yup, got it backwards.. that's what the F1 button is for!! :)  Never trust my memory anymore... #$%#$% growing old(er)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Lotus IBM

From novice to tech pro — start learning today.