Agent Code Error

Hi,

I am trying to create an Agent that saves attachments of incoming mail automatically into a given folder on the Notes Server. I currently have the following code.

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 _ 

				("\\10.139.1.15\sourcing\" & o.Name)

				Call o.Remove

				Call doc.Save( True, True )

			End Forall

		End If

		Call session.UpdateProcessedDoc( doc )

		Set doc = col.GetNextDocument(doc)

	Loop

End If

End Sub

This works great if I set the Agent to an Action Menu Selection and to Selected Documents. However if I set it to On Schedule and New & Modified Documents it fails with the Error “Type Mismatch”. I don’t know which line is causing the error.

Can anyone shed any light on this?

Thanks in advance.

Subject: Agent Code Error

Just curious, what happens when you get 2 files with the same filename? Your code does not appear to handle this scenario.

Subject: RE: Agent Code Error

Hi Paul,

Haven’t tested that yet. Not very good with LotusScript, Admin by nature! Got the original code from the forums and tweaked it a bit. Appreciate any suggestions.

Thanks

Rob

Subject: RE: Agent Code Error

well you would first need to check to see if a file with that name already exists and then add some logic to handle it, maybe increment the file name with a number.

Subject: Agent Code Error

Look in the Designer help for Error Handling so you can add a few lines to output the line the error is occuring on. This is always good practise anyway.

Most likely the issue is being caused by inssuficient rights for the agent or for the server on the ("\10.139.1.15\sourcing" & o.Name) file server

If you add error handling though you will know exactly which line.