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"  )
						'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

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

Function DocsAreCopies ( doc1 As Variant, doc2 As Variant) As Integer
this function compares the Modification History of two documents - if they have
the same anchestor the routine returns true otherwise it returns false
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 )
	length = Len( modify2 )
End If
i = 1
colonapeared = False
	char =Mid( modify1 , i , 1 )
	If Not char = Mid( modify2 , i , 1 ) Then
		done = True
		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
	DocsAreCopies = False
End If
End Function

Un pensiero su “Postjoin event example code for merging documents

  1. Attractive section of content. I just stumbled upon your website
    and in accession capital to assert that I get in fact enjoyed account your blog posts.
    Any way I’ll be subscribing to your augment and even I achievement
    you access consistently fast.

Lascia un commento

Il tuo indirizzo email non sarà pubblicato. I campi obbligatori sono contrassegnati *

Questo sito usa Akismet per ridurre lo spam. Scopri come i tuoi dati vengono elaborati.