Agent to detach document, call email agent and attach

Hello;Hope someone can point me in the right direction. I appreciate any help. I am stuck trying to get a feature working on a database. All the folowing code below is for an agent, “emaildocs”.

A user should be able to select a document, click the menu agent “emaildocs” and the document will be detached (copied) and attached to user email and sent for review. I have it detaching but cannot seem to fetch the user mail account for the attachment

function. I am getting the error “Type Mismatch”.

My humble theory is something to do with

notesUIworkspace and noteswsworkspace going from a view to get user mail file.

Can someone please offer some feedback in simple terms as I am learning this as I go.

Thank you very much in advance.

Declarations:

Dim s_currentsession As NotesSession

Dim db_thisDatabase As Notesdatabase

Dim doc_RecordDoc As Notesdocument

Dim str_runtime As String

Dim int_doccount As Long

Dim int_currentdoc As Long

Dim dc As NotesDocumentCollection

Initilze:

Sub Initialize

Call setup

’ Start with the first row and start looping

Call mainloop

End Sub

Mainloop:

Sub mainloop

Set doc_RecordDoc = dc.GetFirstDocument()

While Not(doc_RecordDoc Is Nothing)

Messagebox doc_RecordDoc.Titleopp(0), MB_OK, “Selecting”

Call detach

Call draft_msg

Call s_currentsession.UpdateProcessedDoc( doc_RecordDoc )

Set doc_RecordDoc = dc.GetNextDocument(doc_RecordDoc)

Wend

End Sub

Setup:

Sub setup

’ Create new objects where necessary and point to the correct view.

Set s_currentsession = New NotesSession

’ Connect to the database, create a query, and execute it.

Set db_thisDatabase = s_currentsession.CurrentDatabase

Set dc = db_thisDatabase.UnprocessedDocuments

End Sub

Detach:

Sub detach

Dim rtitem As Variant

Dim object As NotesEmbeddedObject

Dim handle As Variant

'…set value of doc…

Set rtitem = doc_RecordDoc.GetFirstItem( “deliverable” )

If ( rtitem.Type = RICHTEXT ) Then

Forall o In rtitem.EmbeddedObjects

If ( o.Type = EMBED_ATTACHMENT ) Then

Messagebox o.Source, MB_OK, “Detaching”

Call o.ExtractFile( "c:\temp" & o.Source )

End If

End Forall

End If

End Sub

Draft_msg:

Sub draft_msg

Dim ws As New notesuiworkspace

Dim session As New notessession

Dim uidoc As notesuidocument

Dim doc As notesdocument

Dim db2 As notesdatabase

Dim view2 As notesview

Dim doc2 As NotesDocument

Dim subj As Variant

Dim note As NotesRichTextItem

Dim item As NotesItem

Dim username As New NotesName(session.UserName)

strUser = username.canonical

server$ = session.GetEnvironmentString (“MailServer”, True) 'Get user’s home/mail server

mailfile$ = session.GetEnvironmentString (“MailFile”, True) 'Get user’s mail file name

Set uidoc = ws.currentdocument

Set doc=uidoc.document

Set db2 = session.getdatabase (server$,mailfile$)

’ Set view2 = db2.getview (“Drafts”)

Set doc2 = db2.createdocument

doc2.Form = “Memo”

doc2.Subject =“test”

Call doc2.save(True,False)

Messagebox “A draft message has been created with your selections.”

End Sub

Subject: agent to detach document, call email agent and attach

Hi

Little comentary :

Set uidoc = ws.currentdocument => What is it for ?

Set doc=uidoc.document => What is it for ?

Set db2 = session.getdatabase (server$,mailfile$)

’ Set view2 = db2.getview (“Drafts”)

Set doc2 = db2.createdocument

doc2.Form = “Memo”

doc2.Subject =“test”

I’d write:

call doc2.replaceItemValue(“Form”,“Memo”)

call doc2.replaceItemValue(“Subject”,“test”)

Further,

Did you notice that you are calling the draft msg sub for every selected document ?

It does not seem to be what you said you wanted to do…

Finally :

Call s_currentsession.UpdateProcessedDoc( doc_RecordDoc )

I believe this makes no sense…

HTH

–ian–>

Subject: RE: agent to detach document, call email agent and attach

Thank you Yannick;I am getting to getting to “draft message has been created” running debugger and getting no errors, but it is not bringing up the email and attaching the doc.

Here is the code with your suggestions. Can you please show me how to get the email agent to run with the attached doc?

Sub draft_msg

Dim ws As New notesuiworkspace

Dim session As New notessession

Dim uidoc As notesuidocument

Dim doc As notesdocument

Dim db2 As notesdatabase

Dim view2 As notesview

Dim doc2 As NotesDocument

Dim subj As Variant

Dim note As NotesRichTextItem

Dim item As NotesItem

Dim username As New NotesName(session.UserName)

strUser = username.canonical



server$ = session.GetEnvironmentString ("MailServer", True) 'Get user's home/mail server

mailfile$ = session.GetEnvironmentString ("MailFile", True) 'Get user's mail file name





Set db2 = session.getdatabase (server$,mailfile$)

’ Set view2 = db2.getview (“Drafts”)

Set doc2 = db2.createdocument

Call doc2.replaceItemValue("Form","Memo")

Call doc2.replaceItemValue("Subject","test")



Call doc2.save(True,False)

Call s_currentsession.UpdateProcessedDoc( doc_RecordDoc )



Messagebox "A draft message has been created with your selections." 

End Sub