Can I create an agent to print all attachments?

0 pts.
Tags:
Lotus Agents
Lotus Notes
New Question Created
ASKED: June 27, 2008  5:29 PM
UPDATED: June 30, 2008  2:15 PM

Answer Wiki

Thanks. We'll let you know when a new response is added.

Yes i’ve wrote it with Lotus Script agent (and a call to Windows API)
Declaration Section :

Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (Byval hwnd As Long, Byval lpOperation As String, Byval lpFile As String, Byval lpParameters As String, Byval lpDirectory As String, Byval nShowCmd As Long) As Long

Private Const ERROR_SUCCESS = 32&
Private Const ERROR_NO_ASSOC = 31&
Private Const ERROR_OUT_OF_MEM = 0&
Private Const ERROR_FILE_NOT_FOUND = 2&
Private Const ERROR_PATH_NOT_FOUND = 3&
Private Const ERROR_BAD_FORMAT = 11&

' ***App Window Constants***
Const WIN_NORMAL = 1 	'Open Normal
Const WIN_MAX = 3 			'Open Maximized
Const WIN_MIN = 2 			'Open Minimized

Initialize section :

Dim session As New NotesSession
Dim ws As New NotesUIWorkSpace	

Dim db As NotesDatabase
Dim view As NotesView
Dim uiview As notesuiview
Dim collec As NotesDocumentCollection
Dim doc As NotesDocument
Dim uidoc As NotesUIDocument
Dim rtItem As NotesRichTextItem 
Dim object As NotesEmbeddedObject 

Dim tabTemp As Variant, tabEmbed As Variant, tabFichier() As Variant, tabChamp() As Variant
Dim  nChamp As Integer, nPj As Integer, nChoix As Integer

Set uidoc = ws.CurrentDocument
If uidoc Is Nothing Then

   ' We are in a view
   Set uiview = ws.CurrentView
   Set collec = UIView.Documents
   If collec.count > 0 Then
	Set doc = collec.GetFirstDocument
	Do While Not doc Is Nothing	
		Call PrintPJ( ws, doc )
		Set doc = collec.GetNextDocument( doc ) 
	Loop
   Else 
        Exit Sub
   End If
Else
   Set doc = uidoc.document
   Call PrintPJ( ws, doc ) 
End If
 

User Function :

Function PrintPJ( wsRecu As NotesUIWorkSpace, docRecu As NotesDocument ) 

	Dim sChemin As String,  sFichier As String
	Dim lpOperation As String, lpParameters As String
	Dim nShowCmd As Long, Hwin32 As Long, hwnd As Long

	nShowCmd =  WIN_MIN
	lpOperation = "Print"  
	' lpOperation = "Open"   			'If you want get a printed copy of Filename,change this for "Print"	

	' Recuperation (variable d'environnement systeme) du path pour repertoire temporaire
	sChemin = Environ("Temp")
	If sChemin <> "" Then
		sChemin = sChemin + "\"
	Else
		sChemin = "C:\"
	End If

	nChamp = 0
	Forall item In docRecu.Items
		If item.Type = RICHTEXT Then
			Redim Preserve tabChamp( nChamp ) 
			tabChamp( nChamp ) = item.Name
			nChamp = nChamp + 1
		End If			
	End Forall 

	If  Isempty( tabChamp ) Then 
		Print "No file attached..."
		Exit Function 
	End If	

	Print "Wait..."		
	nPj = 0

	For nChamp = 0 To Ubound( tabChamp ) 
		Set rtitem = docRecu.GetFirstItem( tabChamp( nChamp )  )
		If Not rtitem Is Nothing Then	
			tabEmbed = rtitem.EmbeddedObjects 	
			If Not Isempty(tabEmbed) Then				
				Forall embobj In rtitem.EmbeddedObjects
					If embobj.Type = EMBED_ATTACHMENT Then
						sFichier = embobj.Name
						Set Object = docRecu.GetAttachment( sFichier)
						Call Object.ExtractFile( sChemin + sFichier )
						Hwin32 = ShellExecute( hwnd , lpOperation , sFichier , "" , sChemin , nShowCmd)
						If Hwin32 > ERROR_SUCCESS Then
							sMsg = "Impression de "  + sFichier + " lançé"
						Else
							Select Case Hwin32
							Case ERROR_NO_ASSOC:
								sMsg = "ERREUR : L'extension du fichier "+ sFichier + " est inconnue du système ! "
							Case ERROR_OUT_OF_MEM:
								smsg = "ERREUR : Pas assez de mémoire pour terminer l'opération !"
							Case ERROR_FILE_NOT_FOUND:
								sMsg = "ERREUR : Fichier " + sFichier + " inexistant !"
							Case ERROR_PATH_NOT_FOUND:
								sMsg = "ERREUR : Chemin " + sChemin + " inexistant !"
							Case ERROR_BAD_FORMAT:
								sMsg  = "ERREUR : Mauvais format de fichier !"
							Case Else:
							End Select
						End If
						Print sMsg
					End If			
				End Forall	
			End If	
		End If	
	Next nChamp 

	' Temporisation pour permettre au dernier document d'être imprimé AVANT sa suppression
	Sleep( 10 )

	' On supprime les fichiers que l'on avait détaché avant...
	For nChamp = 0 To Ubound( tabChamp ) 
		Set rtitem = docRecu.GetFirstItem( tabChamp( nChamp )  )
		If Not rtitem Is Nothing Then	
			tabEmbed = rtitem.EmbeddedObjects 	
			If Not Isempty(tabEmbed) Then				
				' On parcours toutes les pieces jointes pour recuperer les noms des ficheirs
				Forall embobj In rtitem.EmbeddedObjects
					If embobj.Type = EMBED_ATTACHMENT Then
						sFichier = sChemin + embobj.Name
						Kill sFichier
					End If			
				End Forall	
			End If	
		End If	
	Next nChamp 

	Print "All files printed !"		

End Function

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following