I have agent which runs on collection of documents. (selected by db.unprocesseddocuments)
Im executing the collection, using loop one by one documents.
In this loop if it satisties some conditions, it changes the stage to complete and validates many fields, and mail to proper persons.
Now my requirement is, i have to print the document after executing before going to next document in the loop.
But we have print method only in uiview and uidocument.
How to overcome from this…
Thnks in advance…
Subject: Printing the document in the loop…
Try this class:
Sub Initialize
Dim printer As New Printer
printer.PrintUnprocessedDocuments
End Sub
[Options]
Option Declare
[Declarations]
Class Printer
'
' Class Printer can print all unprocessed documents in the current database
'
Private m_ws As NotesUIWorkspace
Private m_agentThis As NotesAgent
Private m_sess As NotesSession
Private m_dateTimeNow As NotesDateTime
Private m_uidoc As NotesUIDocument
Sub New
Const TARGET_ALL_DOCS% = 1
Set m_sess = New NotesSession
Set m_ws = New NotesUIWorkspace
Set m_dateTimeNow = New NotesDateTime( "Today" )
Set m_agentThis = m_sess.CurrentAgent
If m_agentThis.Target<> TARGET_ALL_DOCS% Then
Error 9001,|You have not saved your agent with its Target as "All Documents", so it will not correctly process all Unprocessed Documents in this database.|
End If
End Sub
Public Sub PrintUnprocessedDocuments
'
' Print all unprocessed documents in the current database
'
Dim db As NotesDatabase
Dim dcUnprocessed As NotesDocumentCollection
Dim doc As NotesDocument
Set db = m_sess.CurrentDatabase
Set dcUnprocessed = db.UnprocessedDocuments
Set doc = dcUnprocessed.GetFirstDocument()
Do While Not(doc Is Nothing)
' // Your other loop processing goes here.
Me.PrintOneDocument doc
m_sess.UpdateProcessedDoc doc
Set doc = dcUnprocessed.GetNextDocument(doc)
Loop
End Sub
Private Sub PrintOneDocument(doc As NotesDocument)
Const PRINT_COPIES% = 1
Const ITEMNAME_AGENTLOG$="AgentProcessingStatus"
doc.ReplaceITemValue ITEMNAME_AGENTLOG$,|Printed by agent "| & m_agentThis.Name & |" on | & m_dateTimeNow.LocalTime
doc.Save True,False,True
Set m_uidoc = m_ws.EditDocument(False, doc, False)
If Not m_uidoc Is Nothing Then
Print "Printing " & doc.UniversalID
m_uidoc.Print(PRINT_COPIES%)
m_uidoc.Close True
Else
Error 9002,|Cannot open uidocument "| & doc.UniversalID & |" in user interface.|
End If
End Sub
End Class