Attach multiple files to one new form

Hi,

I’m new to lotusscript and just finding my way around.

I’m trying to performing the following sequence.

  1. Detach terms.pdf from selected files.

  2. Detach remaing invoices to local hard drive.

  3. Attach all invoices within that directory to a new form for sending out.

I can remove the terms and conditions and save the invoices to the local drive drive but i’m struggling to work out how to attach all the local invoices back into a new form.

Any help appreciated. Code done so far detailed below :

Sub Initialize

Dim s As New NotesSession

Dim db As NotesDatabase

Dim coll As NotesDocumentCollection

Dim doc As NotesDocument

Dim eo As NotesEmbeddedObject

Dim RTITEM As NOTESrICHtEXTiTEM

Dim Counter As Integer



Set db=s.CurrentDatabase

Set coll=db.UnprocessedDocuments



For a=1 To coll.count

	Set doc=coll.GetNthDocument(a)

	Set rtitem = doc.GetFirstItem("Body")

	Forall o In rtitem.EmbeddedObjects

		

		If o.name = "Terms.pdf" Then

			Call o.remove

		End If

		Call doc.Save( True, True ) 

	End Forall

Next



Counter = 1



For a=1 To coll.count

	Set doc=coll.GetNthDocument(a)

	Set rtitem = doc.GetFirstItem("Body")

	Counter = Counter + 1

	Forall o In rtitem.EmbeddedObjects

		

		oname="c:\Extracted\" + o.name

		Call o.ExtractFile( oname )

		'Messagebox o.name

	End Forall

Next



Dim workspace As New NotesUIWorkspace

Call workspace.ComposeDocument( "", "", "ForwardEmail2" )



Dim filename As String

Dim body As NotesRichTextItem

Dim object As NotesEmbeddedObject



Set db = s.CurrentDatabase

Set doc = db.CreateDocument

Set body = doc.CreateRichTextItem("Body")

doc.Form = "formularz"

filename$ = Dir$("c:\Extracted\*.*")

Do While filename$ <> ""

	Set object = body.EmbedObject(EMBED_ATTACHMENT, "", "c:\Extracted\" & filename$)

	Call doc.Save(True, False)

	' Kill "c:\Extracted\" & filename$

	filename$ = Dir$("c:\Extracted\*.*")

	Messagebox filename$

Loop

End Sub

Subject: So what is it doing wrong?

  • I’d guess it’s stopping after the first file, but what is it really doing?

Subject: Response

Hi,

It’s removing the terms and extracting the invoices to the extracted directory but it only attaches the highlighted documents attachment to the new form and not all of the ones ticked down the left side of the view.

Thanks

Darren

Subject: So it’s not processing all selected documents…

  • Is your Agent set to run on selected documents?- Are you running the Agent from a button in a View?

  • Is this even an Agent? It could be code on a button. I don’t recall how code on buttons work when documents are selected, as opposed to code in an Agent set to run on selected documents.

  • REM out everything except your first loop, the first For a=1 to coll.count. In that loop, Print one field value from the document, any field as long as you know it’s populated and you know it’s not rich text. Select some documents and run the code. The status bar should have one line for each document you selected. If it does, then you are likely iterating over your documents correctly.

  • If it does not, you have a much less complex loop to continue debugging why it’s not processing all the selected documents.

  • You can also (temporarily!) put in Print statements where-ever in your code. They will appear on the status bar when run from the Notes client, and on the server console when run from a scheduled Agent. You may also instantiate an Agent log and use it instead of Print-ing. Look up NotesLog in Help for more information.

  • Hope A) this isn’t too late and B) it helps.

Good luck!