I am using the agent found here:
http://www-10.lotus.com/ldd/nd6forum.nsf/55c38d716d632d9b8525689b005ba1c0/2f1d9c7987c618ab852572c3006f0d58?OpenDocument
I want to run it either as a scheduled agent or when new mail arrives. When I check the log for the agent, I see that it is triggering and identifying the new messages, but no attachments are saved. If I go to the list of agents in Designer and run it from the menu, it saves the attachments as it should. Is it possible for this code to work any other way than being triggered manually? I have also tried signing it with the server’s id but it made no difference either way.
Thanks,
John Rowland
Subject: Agent to save attachments does not work properly
When you run this manually it runs on the client so will save the files to the temp directory on your C Drive. A scheduled agent runs on the server so it will try to save the files to the temp directory on the C drive of the server.
You need to make sure that the temp directory exists on the server and that the signer of the agent has rights to save files to the directory - run unrestricted methods in the server document in the address book. Also look at adding error handling routines to agents that will notify you of where errors are occurring.
Subject: RE: Agent to save attachments does not work properly
Thanks for the reply. Actually, the path has been changed to the root of the d: drive on the mail server (I did not say that in my original post) and I do have rights (as an admin group member) to run unrestricted methods on that server.
As posted before, the agent does save the files there when forced but not when left to run on its own.
Other than the log for the agent itself, is there somewhere else I can look for failure clues?
Thanks
Subject: RE: Agent to save attachments does not work properly
Does the temp directory exist on the root of the D drive? If not it will throw an error.
You will need to provide some error handling to find out what the problem is. This can de done in several different ways by using Print, Msgbox, writing to a log database, sending an email etc.
Using Print in a scheduled agent will write to the notes log so at the start of your code add
On Error GoTo ErrorHandler
and at the end
Exit Sub
ErrorHandler:
Print "Error Message - " & Error & " Code - " & Err & " occurred on line " & Erl
Exit Sub
End Sub
Subject: RE: Agent to save attachments does not work properly
I should have done this to begin with but I wanted to have a pointer back to the thread where I got the code from… the person who posted there had a similar problem.
Here is the real code I am using:
Dim session As NotesSession
Dim db As NotesDatabase
Dim col As NotesDocumentCollection
Dim doc As NotesDocument
Dim rtitem As Variant
Dim fileCount As Integer
Sub Initialize
Set session = New NotesSession
Set db = session.CurrentDatabase
Set col = db.UnprocessedDocuments
If col.Count <> 0 Then
Set doc = col.GetFirstDocument
Do While Not( doc Is Nothing )
Set rtitem = doc.GetFirstItem( “Body” )
If (rtItem.Type = RICHTEXT) Then
Forall o In rtitem.EmbeddedObjects
fileCount = fileCount + 1
If (o.Type = EMBED_ATTACHMENT) Then
Call o.ExtractFile("\midas\d$" & o.Name)
End Forall
End If
Call session.UpdateProcessedDoc( doc )
Set doc = col.GetNextDocument(doc)
Loop
End If
I will look at putting in some error-trapping, as suggested.
Thanks
Subject: Agent to save attachments does not work properly
Let me do a reset here.
My goal:
Remote sites send process data to a a mail file at the home office. The files are detached to a database server folder and picked up by a process data application. The agent runs unattended – does not have to be launched from the UI.
I’m reading two different points of view:
-
It can’t be done because the agent code is not backend code, it is only supported in the UI.
-
It can be done, but failures are probably security related – either Domino or the file system.
Can anyone definitively say which one is correct? They are mutually exclusive answers.
Thanks
John
Subject: RE: Agent to save attachments does not work properly
Let me offer two possibilities to check. One version of the code you posted was trying to save it to a network drive, which won’t work if the server task is running as a system (not logged on) service.
Another suggestion, which I didn’t see anyone mention. In the Agent Properties, security tab (with the key on it) have you selected “Allow restricted operations”? Local file system access is a restricted operation. Also, the signer of the agent must be listed in the server document with the right to run restricted agents.
Subject: Agent to save attachments does not work properly - working now
Thanks.
I did the following:
-
verified that I am listed in the “Run restricted Lotusscript/Java agents” server security field
-
set the agent properties to “3. Allow restricted operations with full Administration rights”
-
set the agent properties to run on schedule against all new and modified documents
-
mapped a drive from the mail server to different server for testing purposes
-
added the appropriate folder to the mapped drive
It is working as expected. Thanks to all for the input.