Desperately seeking Susan …
I’ve got this LS agent code, which works just fine when run from the menu.
It detachs all file attachments from the document and writes them to a common directory.
However, when I set the trigger for this same agent to execute when “after new mail arrives”, it fails …
Server console outputs an “Object Variable Not Set” error …
Sub Initialize
Dim session As New NotesSession
Dim doc As NotesDocument
Dim rtitem As Variant
Dim strOutput As String
Set doc = session.DocumentContext
Set rtitem = doc.GetFirstItem( "Body" )
If (rtitem.Type = RICHTEXT) Then
Forall o In rtitem.EmbeddedObjects
If (o.Type = EMBED_ATTACHMENT) Then strOutput = "c:\backup\attachments\" & o.Name
If (Dir$(strOutput) <> "") Then Kill strOutput
End If
Call o.ExtractFile(strOutput)
End If
End Forall
End If
End Sub
Subject: new mail agent [LS] and Object Variable not set error message
Couple of things to consider:
-
When the agent is set to run after new mail arrives, where does it run - I think on the server.
-
Does the notes server have the capability to write to it’s hard drive - admin, user id, etc
-
Does the directory already existi on the server?
-
Can you print a more elaborate error code to understand which object variable is not set?
HTH
Don
Subject: RE: new mail agent [LS] and Object Variable not set error message
. When the agent is set to run after new mail arrives, where does it run - I think on the server. >>> Yes, with the “after new mail arrives” trigger… it runs on the server
- Does the notes server have the capability to write to it’s hard drive - admin, user id, etc
yes
- Does the directory already exist on the server?
yes
- Can you print a more elaborate error code to understand which object variable is not set?
that’s what I am trying to figure out … as the server console outputs only bare minimal text …“object variable not set”
Subject: RE: new mail agent [LS] and Object Variable not set error message
If you included actual error trapping code, the server console would provide more than the bare minimal text…
Sub Initialize
on error goto errhand
Dim session As New NotesSession
Dim doc As NotesDocument
Dim rtitem As Variant
Dim strOutput As String
Set doc = session.DocumentContext
Set rtitem = doc.GetFirstItem( “Body” )
If (rtitem.Type = RICHTEXT) Then
Forall o In rtitem.EmbeddedObjects
If (o.Type = EMBED_ATTACHMENT) Then strOutput = "c:\backup\attachments" & o.Name
If (Dir$(strOutput) <> “”) Then Kill strOutput
End If
Call o.ExtractFile(strOutput)
End If
End Forall
End If
exit sub
errhand:
print "error at line " & erl & ": " & error
exit sub
End Sub
Subject: new mail agent [LS] and Object Variable not set error message
You are setting your doc using document context, I thought this was only for web based agents but I could be wrong - it might work for “when new mail arrives” agents.
Perhaps doc is not getting set because of this and this is your object variable not set error.
You only have 2 objects (in your posted code) that might generate this error, your doc and your rtitem, one of these is not getting set for whatever reason - perhaps the doc has not been saved which would be your rtitem not being avaailable or is the doc -
Try adding print statements so you can see how far your code is getting. The output of your print statements should appear on the server console / log.nsf.