Here's the code I've used to do it manually. How can this be tweaked to run from the server on a scheduled basis? If I use the code as is, in an agent set to run on a schedule, it does not run.
Sub Initialize Dim session As New NotesSession Dim db As NotesDatabase Dim doc As NotesDocument Dim dc As NotesDocumentCollection Dim rtitem As Variant Dim attachname As String Dim filename As String Dim body As NotesRichTextItem Dim emphasize As NotesRichTextStyle Set db = session.CurrentDatabase Set dc = db.UnprocessedDocuments Set doc = dc.GetFirstDocument Set rtitem = doc.GetFirstItem( "Body" ) If ( rtitem.Type = RICHTEXT ) Then Forall obj In rtitem.EmbeddedObjects If ( obj.Type = EMBED_ATTACHMENT ) Then Set emphasize = session.CreateRichTextStyle emphasize.Bold = True emphasize.NotesColor = COLOR_RED Set body = doc.GetFirstItem("Body") Call rtitem.AddNewLine( 2 ) Call body.AppendStyle(emphasize) attachname = obj.source Call obj.ExtractFile ( "\\ QDSWJDE1AMstarUnProcessed\" & attachname ) Call rtitem.AddNewLine( 2 ) Call rtitem.AppendText(( "Your file was downloaded to\ \QDSWJDE1AMstarUnProcessed as filename: " ) & attachname) Call doc.Save( False, True ) End If End Forall End If End Sub
Writing to the file system is a "restricted" operation, and for your agent to be able to do it, two things must be true. First, the ID that signed the agent must have access to run restricted agents. This is set in security tab of the server configuration document in the server's names.nsf. Second, the agent properties must have a "runtime security level" set to 2 or 3 -- the default is 1, which does not allow restricted functions.
One other consideration: it may be necessary to map the drive on the server so that you can specify the path using a drive letter (or, more generally for other server platforms, as a filepath that appears to be local).
Do you have comments on this Ask the Expert question and response? Let us know.
This was first published in March 2005