Solved

Agent works running on client, but not when server runs on new mail arrival.

Posted on 2002-04-22
10
300 Views
Last Modified: 2013-12-18
Hello Everyone, hope you are all well..

I have an agent that is going to run from a mail-in db to update a different database (documents with a ref no matching the last 4 characters of the memo subject)to create a response 'comments' doc.

The code works fine when I run it 'Manually from actions menu', but not on 'After New Mail has arrived' - I think this is because it is running on the server and not on the client by me..

Anyway here's the code:-

**********************************************************

Sub Initialize
     Dim s As New NotesSession
     Dim db As NotesDatabase
     Dim doc As NotesDocument, doc2 As NotesDocument, NewDoc As NotesDocument
     Dim dc As NotesDocumentCollection
     Dim view As NotesView
     Dim CurrentLog As New NotesLog( "SS53 Process Carrier mails" )
     
     Dim sRefNo As String, sPath As String, sServer As String
     Dim x As Integer
     
     Set db = s.CurrentDatabase
     Set dc = db.UnProcessedDocuments
     Call CurrentLog.OpenNotesLog( db.server,"agentlog.nsf" )    
     Call CurrentLog.LogAction("Started running script") 'Copy, paste and amend this line to change agent log text        
     
     Call CurrentLog.LogAction("Sent e-mail")    
     '****** tmp e-mail msg
     Dim Message As NotesDocument
     Set Message = db.CreateDocument                    
     With message
          .Form = "Memo"
          .SendTo = "Ian Wood"
          '.CopyTo = "Chris Stenton"
          .Subject = "Bingo"
          .Logo = "First Initial"
          .SaveOptions = 0
     End With
     Call Message.Send(False)      
     
     If Not (dc.count > 0) Then
          Call CurrentLog.LogAction("No docs found")
          Exit Sub
     End If
     Call CurrentLog.LogAction("1 or more documents found to run on..")
     
     sServer = "NHTNTDV0"'GetProfileValue("Setup", "Server")
     sPath = "Development\CSC\CSC_SS53_2-0.nsf"'GetProfileValue("Setup", "Path")
     Dim db2 As New NotesDatabase(sServer,sPath)
     
     If (Not db2.Open(sServer,sPath)) Then
         
          'Msgbox "Unable to open the SS53 db.",64,db.title      
          Call CurrentLog.LogAction("unable to open target SS53 db!!!")
         
          Exit Sub
     End If
     Call CurrentLog.LogAction("Opened target SS53 db")
     Set view = db2.GetView("(LookUpRefNo)")
     
     For x = 1 To dc.count
          Call CurrentLog.LogAction("In processing loop no: " & x)
          Set doc = dc.GetNthDocument(x)
          sRefNo = Right(doc.Subject(0),4)
          Set doc2 = view.GetDocumentByKey(sRefNo, True)
          Set NewDoc = New NotesDocument(db2)
          NewDoc.Form = "Comment"
          NewDoc.Subject = doc.Subject(0)
          NewDoc.Body = doc.Body
          Call NewDoc.MakeResponse(doc2)
          Call NewDoc.save(True, False)          
     Next
     Call CurrentLog.Close    
End Sub

**********************************************************

I've only ever written code that is executed on the client.  At the moment it is getting stuck (As far as I can tell it just stops running) on the opening of the target db (db2), but I don't know how else to write it..

Anybody got any ideas?

Cheers

Ian


0
Comment
Question by:IanWood
  • 4
  • 2
  • 2
  • +2
10 Comments
 
LVL 10

Expert Comment

by:zvonko
ID: 6959874
Support for accessing remote servers from server-based agents is coming in Rnext :-)

Look here for Julie's description:
http://www.notes.net/46dom.nsf/7e6c7e584a76331b85256a46006f083e/574c99ccb345839185256976004e811e?OpenDocument

0
 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 6959877
What does the log say ?

There are some rules by which the scheduled agent runs on server. Basically the security. So you have to see the signature on agent is validated by other server. Probably the agent execution access is not setup propertly on target server.

Here are two excellent articles on agent functionality, check it out. It is worth spending some time to read this articles and in future it will be much handy.

http://notes.net/today.nsf/62f62847467a8f78052568a80055b380/08f2d1ce0329d70e852565a2005227e6?OpenDocument

http://notes.net/today.nsf/62f62847467a8f78052568a80055b380/27f79cb66e381900852565b6006d2eb4?OpenDocument

~Hemanth
0
 

Author Comment

by:IanWood
ID: 6960030
The log says what it's supposed to, up until after the db open bit and then it is blank..

I'm just going to have a read of the links now cos I really need to get this working!!

Cheers

Ian
0
 

Expert Comment

by:srandrews
ID: 6960213
Ian,

Are both databases on the same server? Running the code on your client would work, but due to security the server where the code is running wouldn't be able to access a db on another server.

This is just an idea as you should get an error message in the log if this is the case.

Simon
0
 

Author Comment

by:IanWood
ID: 6960326
Hi Simon - No, they are on different servers (the Mail-in is on our mail server and the target db is on our development server (and it'll be moved to an application server once it's completed)!! I was hoping to have the target server and path as parameters in the mail-in db..

Heman, where you on about the agent log from the agents screen in design mode or the Notes Agent log I'm outputting debug msgs to?  The log from the agent screen in the mail-in db tells me that the agent has run and the agent log I'm writing to only has the comments up until the db open line..

Zvonko/anyone, does that mean that I can't access a different server than the one it is running on?  What would I need to do to get access?  If I put them both on the same server (administrators won't like me!!)would it work?  Is the actual code alright for running on a server (I've already removed the rather stupid NotesUIWorkspace declaration I had in to start with!!)?

I've looked through the attached links and I have to admit, I'm a bit confused..  Too much information for me to take in for the time-being!!  i think I'm running a background agent on the server and I'm the 'Owner' , not sure about 'Invoker' (Would this be the server, not me?) and I have manager rights to both db's..

Right, doesn't sound as simple as I thought it'd be('Change line x to read blah blah etc.'), so I'm going to up the points a bits..

Cheers

Ian

0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

by:IanWood
ID: 6960338
Hi Simon - No, they are on different servers (the Mail-in is on our mail server and the target db is on our development server (and it'll be moved to an application server once it's completed)!! I was hoping to have the target server and path as parameters in the mail-in db..

Heman, where you on about the agent log from the agents screen in design mode or the Notes Agent log I'm outputting debug msgs to?  The log from the agent screen in the mail-in db tells me that the agent has run and the agent log I'm writing to only has the comments up until the db open line..

Zvonko/anyone, does that mean that I can't access a different server than the one it is running on?  What would I need to do to get access?  If I put them both on the same server (administrators won't like me!!)would it work?  Is the actual code alright for running on a server (I've already removed the rather stupid NotesUIWorkspace declaration I had in to start with!!)?

I've looked through the attached links and I have to admit, I'm a bit confused..  Too much information for me to take in for the time-being!!  i think I'm running a background agent on the server and I'm the 'Owner' , not sure about 'Invoker' (Would this be the server, not me?) and I have manager rights to both db's..

Right, doesn't sound as simple as I thought it'd be('Change line x to read blah blah etc.'), so I'm going to up the points a bits..

Cheers

Ian

0
 

Accepted Solution

by:
srandrews earned 200 total points
ID: 6960350
Ian,

Sorry, I didn't word my comment properly!

An agent running on one server cannot access a database on another server. I imagine the two links from Herman will go into detail about this.

When you run the agent from your client you can access both servers as long as you have access to both.

Simon
0
 

Author Comment

by:IanWood
ID: 6960402
Arhhh, that'll be it then (although I don't seem to get any error messsages, it just stops running).. I'm sure it was in the links somewhere, but agents are new to me, so probably missed it in all the detail!!

So, to get it to work I have to have them on the same server, or employ someone to manually run the agent when new mail arrives!!  ;-)

Is there any workarounds possible, or will I have to annoy our administrators and insist that the app goes on the mail server with the Mail-In?
0
 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 6960711
That is how the architecture laid out. So keep it on one server to avoid this problem.

0
 
LVL 8

Expert Comment

by:Jean Marie Geeraerts
ID: 6962552
Just to confirm what others have said:
You can only access databases that are on the same server when running the agent on the server.

A tip for debugging agents :

Create scheduled agents using this framework to have complete debugging information :

Sub Initialize
    REM Initialize session and variables for the agent log
    Dim session As New NotesSession
    Dim agent as NotesAgent
    Dim db as NotesDatabase
    Dim agentLog as NotesLog
    'Define the path to the agents log database to log to
    Const LogFile$="logs/agents.nsf"
    Dim LogServer as String

    Set agent=session.CurrentAgent
    Set db=session.CurrentDatabase
    LogServer=db.Server

    REM Open agentlog and define error routine
    Set agentLog=New NotesLog(db.Title + " - " + agent.Name)
    Call agentLog.OpenNotesLog(LogServer, LogFile$)
    On Error Goto LogError
    Call agentLog.LogAction("Agent started at " + Cstr(Time))

    REM Start the regular part of your agent here
    REM Write debugging info to the log using LogAction method

    REM Close agent log and exit
    Call agentLog.LogAction("Agent finished at " & Cstr(Time))
    Call agentLog.Close
    Exit Sub

LogError:
    REM Error catching routine : logs the error to the agent log
    Call agentLog.LogError(err, "Initialize: " & Error$ & " in line " & cstr(Erl))
    Resume Next
End Sub


To log detailed information in subroutines always include an extra on error goto and error catching routine for each sub you want to have debug info on.

An example:

Sub RoutineWithDebugInfo
    REM Define local error routine
    REM You don't need to open the agent log, since this is opend in Initialize
    On Error Goto LogLocalError

    Exit Sub
LogLocalError:
    Call agentLog.LogError(Err, "RoutineWithDebugInfo: " & Error$ & " in line " & Cstr(Erl))
    Resume Next
End Sub

I hope you can use this to debug future problems. If you use this debugging info, you will always be able to find an error message if something goes wrong in your agent.
If you don't write debugging info like this, with a resume command, the agent just stops running if an error is encountered.

The agent log database is created using the Agent Log database.

If you need any further info on this, just let me know.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

I thought it will be a good idea to make a post as it will help in case someone else faces these issues. I trust this gives an idea how each entry in Notes.ini can mean a lot for the Domino Server to be functioning properly. This article discusses t…
  In today’s Arena we can’t imagine our lives without Internet as we are highly used to of it. If we consider our life style just for only 2 min we found that face to face communication is swapped by e-communication.  Every Where from Works place to…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now