Lotus Notes “Check Attachments”

IBM Lotus Domino In which databases are hidden large attachments?
What are the mailboxes with the largest number of large attachments?
Size of messages that pass through our Domino router?
I can tell a user to delete that attachment so much from his mailbox?

These and similar questions are posed to me by some of the managers of information systems that use Lotus Domino: Lotus Domino is accompanied by a number of functions that allow you to better manage e-mail and there are also numerous third-party tools, but the file attached here is a Lotus Notes application that I developed using open source applications, and other parts that I put at your disposal.

The key point is the application “Application Profile” where you have to specify the server and the path on which to search the databases then you will want to scan (to look for in each for any attachments are too large).

If in the domino server is enabled “Message Tracking” is also possible to select the desired date and export  mtstore data in csv format for further analysis later in Excel.

It is important that the user has access as a Manager in each of the files to scan as well as the mtstore.nsf file.

The ui interface is Italian (mostly) but I think sould be easy to translate in other languages.

Download here: Check Attachments (899)

Aggiornare dinamicamente campi rich-text con LotusScript

Di seguito la traduzione di un articolo che illustra come gestire tramite LotusScript gli allegati in un campo rich-text sul documento Lotus Notes aperto sul front-end.

Aggiornare dinamicamente campi rich-text con LotusScript

Titolo originale: “Dynamically update Lotus Notes rich-text fields using LotusScript”

Autore: Amith Narera
11.20.2007

Una modifica effettuata su un documento Lotus Notes nel back-end viene solitamente riprodotta nel documento di front-end, ma u’eccezione a questo comportamento sono i campi di tipo rich-text. Per le modifiche ai campi rich-text, si deve chiudere il doumento Lotus Notes di front-end e aprirlo di nuovo usando il metodo NotesUIWorkspace.EditDocument. Comunque, questo fa “scatenare” tutti gli eventi associati alla form Lotus Notes. Questo tip aggira questo problema consentendo di aggiornare dinamicamente i campi rich-text del front-end senza chiudere e riaprire la form Lotus Notes principale.

A scopo esemplificativo, aggiungo l’attuale username Lotus Notes, l’ora di sistema e gli allegati (selezionati dall’utente Lotus Notes) al campo rich-text. Il seguente codice LotusScript consente anche di appendere item rich-text da un altro documento Lotus Notes (codice commentato).

Quello che segue è uno schema di come il codice LotusScript lavora:

  • Crea un documento Lotus Notes “di appoggio” nel back end usando il metodo db.CreateDocument.
  • Aggiunge un campo rich-text al documento.
  • Esegue tutte le azioni necessarie su questo campo rich-text .
  • Apre il documento Lotus Notes nel front-end coun una form “di appoggio” che contine solamente un campo rich-text (con lo stesso nome di quello creato nel secondo passaggio visto prima).
  • posiziona il cursore in questo campo rich-text, seleziona tutto il testo, e copia tutto negli appunti.
  • Chiude la form Lotus Notes “di appoggio”.
  • Va sul campo rich-text di destinazine sulla form Lotus Notes principale.
  • Incolla tutto dagli appunti.
  • Missione eseguita.

Questi sono gli step necessari per ottenere il risultato desiderato:

  1. Create a new form. Name it “Dummy Form.”
  2. Place a rich-text field, named “DummyRT” on it.
  3. Open your main Lotus Notes form where you’d like these updates to happen.
  4. Create a new Action button, and name it “Update RT Field.” You may use the LotusScript code anywhere. For the sake of simplicity I am using it in a button.
  5. Select LotusScript as the coding language and paste the code given below into it.
Sub Click(Source As Button)
   Dim workspace As New NotesUIWorkspace
   Dim session As New NotesSession

'COMMENT #######> UiDoc represents the currently open Fron End document, where the rich text field exists.
   Dim uidoc As NotesUIDocument

'COMMENT #######> Dummy UIDoc ---needed by the code
   Dim DummyUIDoc As NotesUIDocument
   Dim db As NotesDatabase

'COMMENT #######> Back End version of DummyUIDoc
   Dim DummyDoc As NotesDocument

'COMMENT #######>  RT Item in DummyDoc ---From where you would be pulling the changes
   Dim DummyRT As NotesRichTextItem
   Dim FilePath As Variant

   Set db = session.CurrentDatabase
   Set uidoc = workspace.CurrentDocument

   Set DummyDoc = db.CreateDocument

'COMMENT #######> Set Fields for Dummy Document
   DummyDoc.Form = "Dummy Form" ' NOTE: It shud be dummy form, not your main form.
   DummyDoc.SaveOptions = "0"

'COMMENT #######> Get the File path for the file to be attached
    FilePath = workspace.OpenFileDialog(True, "Select Files")

'COMMENT #######> Insert RT Field
   Set DummyRT = New NotesRichTextItem(DummyDoc,"DummyRT")

'COMMENT #######> Update the Field- as per your requirements
   Call DummyRT.AppendText(session.CommonUserName & " - ")
   Call DummyRT.AppendText(Cstr(Now))
   Call DummyRT.AddNewline(1)

'COMMENT #######> Embed Selected Files, if Any
   If Not Isempty(FilePath) Then
      Forall CurrentFilepath In FilePath
         Call DummyRT.EmbedObject(1454,"", CurrentFilePath)
      End Forall
   End If
'COMMENT #######> You may also append an RT Item from any other document. eg.
%REM
    Dim RTItemB As NotesRichTextItem
    Set RTItemB = DocB.GetFirstItem("RTItemName")
    Call DummyRT.AppendRTItem(RTItemB)
%END REM

'COMMENT #######> Call this to commit all the RT Item Changes to the Document
   Call DummyRT.Update

'Here is the Trick
'****************************************************************************
   Set DummyUIDoc =  workspace.EditDocument(True,DummyDoc)
   Call DummyUIDoc.GotoField("DummyRT")
   Call DummyUIDoc.SelectAll
   Call DummyUIDoc.Copy
   Call DummyUIDoc.Close(True)
'COMMENT #######> Goto Main doc Rich Text Field (desitnation field)
   Call uidoc.GotoField("RTF")
   Call uidoc.Paste

'********************************************************************
   Messagebox "Process Completed Successfully.", 64, "Complete"
End Sub

Now — with a click of this action button — you can update the front end of your rich-text item in real-time without having to close and re-open the main Lotus Notes document. You can also apply the same logic to move contents of one rich-text item to the other rich-text item on the same form in real time — without having to re-open the front end document. If you’d like to do that, this code will help you:

   Call UIDoc.GotoField("FirstRT")
   Call UIDoc.SelectAll
   Call UIDoc.Copy
   Call uidoc.GotoField("SecondRT")
   Call uidoc.Paste

Postjoin event example code for merging documents

You use a combination of custom attributes on the joining activity and code in the OS application event script library to get this to work. Below you will find some code and a brief description:

– Paste code below in the ‘PostJoin_’ event in the OS Application Events Script Library

– Add 2 Custom Attributes on the Merge Activity:

PostJoinMergeItems = “YES”;

Merge = array of fields to merge on the MainDoc

Private Function PostJoin_(Cover As NotesDocument,BinderCol As Variant)
Dim binder As Variant
Dim maindoc As NotesDocument
Dim doc As NotesDocument
Dim mainitem As NotesItem
Dim itemnames As Variant
Dim ErrorCode As Integer
Dim ErrorMsg As String
Dim k As Integer
Dim strFieldLabel As String
Dim curValue As String
Dim intModuleAlias As Integer
Dim arrVariant As Variant
Dim item As NotesItem
Dim RTitem As NotesRichtextitem
Dim RTitemMaindoc As NotesRichtextitem
Dim itemType As Integer
Dim intSaveMain As Integer

On Error Goto printError
' Get all documents in the binder
binder = DWFBinderGetDocumentList ( Cover )

' Identify the main document and check whether this code should run
Set maindoc = DWFBinderGetMainDocument ( Cover )

If (Ucase( maindoc.PostJoinMergeItems ( 0 )) = "YES" ) Then
	' Get the list of fields to merge
	itemnames = maindoc.Merge
	Forall b In binder
		' Only process documents that are not the main or cover document
		If Not (Ucase( b.CoverDocOS ( 0 )) = "YES" Or Ucase( b.MainDocOS ( 0 )) = "YES" ) Then
			Set doc = b
			' Check whether doc is a copy of the main document
			If DocsAreCopies ( maindoc , doc ) Then
				' Loop over all items that have to be merged
				Forall fieldName In Itemnames
					' eventuele niet parallele velden moeten appended worden onder het veld in het main-doc
					strFieldLabel = fieldName
					curValue = doc.getitemvalue( fieldName)(0)
					' Get the value from the item and append it to the item on the main document, without having to convert it to text
					If doc.HasItem( strFieldlabel ) Then
						'Let op ! Als het item wel op het doc staat en ook op het maindoc, dan overschrijft ..
						' .. dit de waarde op het main doc !! Daarom check op leeg !!!
						If Not curValue = "" Then
							Call maindoc.replaceItemValue( strFieldLabel, curValue )
							intSaveMain = intSaveMain + 1
						End If
					End If
				End Forall
				'save maindoc to still have reference to the old doc before deleting it
				If intSaveMain > 0 Then
					Call maindoc.Save (True, False)
				End If
				If DWFBinderConsolidate(doc, ErrorCode, ErrorMsg) Then
					' Remove this document from the binder and then delete it
					If DWFBinderRemoveDocument ( doc , False, "" , True, ErrorCode , ErrorMsg ) Then
						Call doc.replaceitemvalue( "RemoveStatus", "yes"  )
						Call doc.save(True,True,True)
						'Remove document later ....
						'Call doc.Remove(True)
					End If
				End If
			End If
		End If
	End Forall
	' Save the main document
	Call maindoc.Save (True, False)
End If
Exit Function

printError:
	Print "Error" & Str(Err) & ": " & Error$ & "Line=" & Erl
	Print "ERROR While joining"
	End Function

Function DocsAreCopies ( doc1 As Variant, doc2 As Variant) As Integer
%REM
this function compares the Modification History of two documents - if they have
the same anchestor the routine returns true otherwise it returns false
%END REM
Dim done As Integer
Dim char As String
Dim length As Integer
Dim i As Integer
Dim colonapeared As Integer
Dim modify1 As String
Dim modify2 As String
' get modify histories
modify1 = doc1 . DocModifyOS ( 0 )
modify2 = doc2 . DocModifyOS ( 0 )
' set len to the length of the shortest of both strings
If Len( modify1 )<Len( modify2 ) Then
	length = Len( modify1 )
Else
	length = Len( modify2 )
End If
i = 1
colonapeared = False
Do
	char =Mid( modify1 , i , 1 )
	If Not char = Mid( modify2 , i , 1 ) Then
		done = True
	Else
		If char = ";" Then
			colonapeared = True
		End If
		i = i + 1
	End If
Loop Until done Or colonapeared Or i > length
If colonapeared Then
	' both activities have a common predecessor
	DocsAreCopies = True
Else
	DocsAreCopies = False
End If
End Function