Skip to main content link. Accesskey S
  • Help
  • HCL Logo
  • HCL Notes and Domino Application Development wiki
  • THIS WIKI IS READ-ONLY. Individual names altered for privacy purposes.
  • HCL Forums and Blogs
  • Home
  • Product Documentation
  • Community Articles
  • Learning Center
  • API Documentation
Search
Community Articles > Troubleshooting > LotusScript function to compare the items of two documents
  • Share Show Menu▼
  • Subscribe Show Menu▼

Recent articles by this author

When 38.3 - 38 equals 0.299999999999997... and what to do about it

Obviously I forgot about the "fraction()" function, so I removedchanged parts of this article (thanks @Mario for the hint) :)   If you need the digits behind the decimal seperator of a number, you might subtract the integer of the number from the number itself: 1.3 int(1.3) e.g. would result ...

When rounding 0.5 equals 0... and what to do about it

Do you know the difference between rounding a number commercially and rounding it mathematically? Notes does... This is, why in Formula @Round(0.5; 1) equals 1, but the equivalent in LotusScript round(0.5, 0) equals 0... Wonder if round(1.5, 0) equals 1? No, the result is...: 2 The reason is, that ...

The third SaveOptions value, or How to suppress the "Do you want to save this document?" message box in Notes

Yes, SaveOptions understands more than just "0" or "1": Did you ever face the problem, that Lotus Notes keeps asking if you want to save the current document, even though you just did? Picture the following scenario: A user creates a document with a certain form that contains a "Change Field ...

Pitfall on NotesUiDocument vs. NotesDocument field changes - unexpected "Reload"

When performing mixed changes on fields, i.e. changing fields in a NotesUiDocument and others in the corresponding backend NotesDocument, it is very important to make sure that they do not have any sideeffects on each other. Could be ugly...   To see what I mean, try this one:   Build a simple ...

Forgotten Notes Features: $PaperColor

Anyone remember, and actually uses (besides in his memos, maybe not knowing) the field "PaperColor" in Lotus Notes documents? Using this field, you can set a dynamic background color in your documents. The field needs to be numeric and contain a number from 1 to 238; usually this field will be ...
Community articleLotusScript function to compare the items of two documents
Added by ~Frank Quetlupulikle | Edited by ~Frank Quetlupulikle on March 3, 2010 | Version 5
  • Actions Show Menu▼
expanded Abstract
collapsed Abstract
No abstract provided.
Tags: Troubleshooting Conflicts Compare NotesDocument NotesItem Item

I want to share a little LotusScript code that compares the items of two documents, and which can be used e.g. to compare conflict documents.

 

The main function is "compareDocuments" which expects the two documents as parameters.
Adjust the constant "LOGFILEPATH" for the filepath of the log output.

 

The comparison goes step by step, from checking the existence in the other document, to the item types, to the item values.

 

Why do I use lists of a class CL_ItemCompare? Because it is slightly faster to read the items once and then access the cached information than to have to access the documents twice for the same information (as it would be the case in the second items loop in the function "compareDocuments").

 

'CompareDocuments: 

Option Public

Option Declare

Class CL_ItemCompare

 Public itName As String
 Public itType As String
 Public itValues As Variant
 Public isChecked As Boolean
 Sub new(it As NotesItem)
  Me.itName = it.Name
  Me.itType = it.Type
  Me.itValues = it.Values
  Me.isChecked = False
 End Sub
End Class
Function compareDocuments(doc1 As NotesDocument, doc2 As NotesDocument) As Boolean
 
 On Error Goto errorhandler
 
 Const LOGFILEPATH = "C:\\comparedocs.txt"
 
 Open LOGFILEPATH For Output As #1
 
 Print #1, "Comparing [" & doc1.UniversalID & "], [" & doc2.UniversalID & "]"
 
 
 ' get all items from doc1
 Dim listItCompare1 List As CL_ItemCompare
 Dim itx As NotesItem
 If Not Isempty(doc1.Items) Then
  Forall it In doc1.Items
   Set itx = it
   Set listItCompare1(Lcase(itx.name)) = New CL_ItemCompare(itx)
  End Forall
 End If
 
 ' get all items from doc2
 Dim listItCompare2 List As CL_ItemCompare
 If Not Isempty(doc2.Items) Then
  Forall it In doc2.Items
   Set itx = it
   Set listItCompare2(Lcase(itx.name)) = New CL_ItemCompare(itx)
  End Forall
 End If
 
 ' compare all items of doc1 with items in doc2
 Forall itCompare1 In listItCompare1  
  If Not compareItems(itCompare1, listItCompare1, listItCompare2) Then Goto e
 End Forall
 
 ' all items of doc2 that have not been treated yet are missing in doc1
 Forall itCompare2 In listItCompare2
  If Not itCompare2.isChecked Then
   Print #1, "Item '" & itCompare2.itName & "': [DOES NOT EXIST, exists]"
  End If
 End Forall
 
 compareDocuments = True
e:
 Close
 Exit Function
errorhandler:
 Msgbox "compareDocuments: Error " & Error & " in line " & Erl
 Resume e 
End Function

Function compareItems(itCompare1 As CL_ItemCompare, _

listItCompare1 List As CL_ItemCompare, _
listItCompare2 List As CL_ItemCompare) As Boolean
 
 On Error Goto errorhandler
 
 itCompare1.isChecked = True
 
 ' check if item of doc1 exists in doc2
 If Not Iselement(listItCompare2(Lcase(itCompare1.itName))) Then
  Print #1, "Item '" & itCompare1.itName & "': [exists, DOES NOT EXIST]"
  compareItems = True
  Exit Function
 End If
 
 ' get item of doc2
 Dim itCompare2 As CL_ItemCompare
 Set itCompare2 = listItCompare2(Lcase(itCompare1.itName))
 itCompare2.isChecked = True
 
 ' compare types
 If itCompare1.itType <> itCompare2.itType Then
  Print #1, "Item '" & itCompare1.itName & ": type = [" & itCompare1.itType & _
  ", " & itCompare2.itType & "]"
  compareItems = True
  Exit Function
 End If
 
 ' compare typename of values
 If Typename(itCompare1.itValues) <> Typename(itCompare2.itValues) Then
  Print #1, "Item '" & itCompare1.itName & ": typename of values = [" & _
  Typename(itCompare1.itValues) & ", " & Typename(itCompare2.itValues) & "]"
  compareItems = True
  Exit Function
 End If
 
 ' compare item values
 
 Dim isEqual As Boolean
 Dim i As Integer
 Dim txtValue1 As String
 Dim txtValue2 As String
 Dim isFirst As Boolean
 
 If Instr(Typename(itCompare1.itValues), "( )") > 0 Then ' compare arrays
  
  ' compare ubound of item values array
  If Ubound(itCompare1.itValues) <> Ubound(itCompare2.itValues) Then
   Print #1, "Item '" & itCompare1.itName & ": ubound(values) = [" & _
   Ubound(itCompare1.itValues) & ", " & Ubound(itCompare2.itValues) & "]"
   compareItems = True
   Exit Function
  End If
  
  ' compare single array entries
  isEqual = True
  For i = 0 To Ubound(itCompare1.itValues)
   If itCompare1.itValues(i) <> itCompare2.itValues(i) Then
    isEqual = False
    Exit For
   End If
  Next
  
  If Not isEqual Then
   
   ' concatenate values (we cannot use join here if values are e.g. array of integers)
   txtValue1 = ""
   isFirst = True
   Forall x In itCompare1.itValues
    If Not isFirst Then
     txtValue1 = txtValue1 & ";"
    Else
     isFirst = False
    End If
    txtValue1 = txtValue1 & Cstr(x)
   End Forall
   
   ' concatenate values (we cannot use join here if values are e.g. array of integers)
   txtValue2 = ""
   isFirst = True
   Forall x In itCompare2.itValues
    If Not isFirst Then
     txtValue2 = txtValue2 & ";"
    Else
     isFirst = False
    End If
    txtValue2 = txtValue2 & Cstr(x)
   End Forall
   
   Print #1, "Item '" & itCompare1.itName & ": values = [" & txtValue1 & ", " & txtValue2 & "]"
   compareItems = True
   Exit Function
   
  End If 
  
 Else ' compare single value (i.e. NotesRichtextItem.Values)
  
  If itCompare1.itValues <> itCompare2.itValues Then
   Print #1, "Item '" & itCompare1.itName & ": values = [" & itCompare1.itValues & _
   ", " & itCompare2.itValues & "]"
   compareItems = True
   Exit Function
  End If
  
 End If
 
 ' items are equal
 Print #1, "Item '" & itCompare1.itName & ": is equal"
 
 compareItems = True
e:
 Exit Function
errorhandler:
 Msgbox "compareItems: Error " & Error & " in line " & Erl
 Resume e 
End Function
Sub Terminate
 
End Sub

 

About the Author
Marcus Foerster works as Systems Architect for Pentos AG in Munich, Germany. His focus lies on the application side, creating collaboration systems for users, groups and enterprises to get their daily work done. This approach includes integrating complex workflows with intuitive user interfaces, using Lotus Notes/Domino with Adobe Flex and other Web technologies.
Read more in Marcus' blog: http://marcus.foerster.com/blogexternal link


  • Actions Show Menu▼


expanded Attachments (0)
collapsed Attachments (0)
Edit the article to add or modify attachments.
expanded Versions (5)
collapsed Versions (5)
Version Comparison     
VersionDateChanged by              Summary of changes
This version (5)Mar 3, 2010, 1:46:47 PM~Frank Quetlupulikle  
4Mar 3, 2010, 1:44:55 PM~Hank Nonhipilygon  
3Mar 3, 2010, 1:44:27 PM~Hank Nonhipilygon  
2Mar 3, 2010, 1:42:08 PM~Hank Nonhipilygon  
1Mar 3, 2010, 1:39:37 PM~Hank Nonhipilygon  
expanded Comments (0)
collapsed Comments (0)
Copy and paste this wiki markup to link to this article from another article in this wiki.
Go ElsewhereStay ConnectedAbout
  • HCL Software
  • HCL Digital Solutions community
  • HCL Software support
  • BlogsDigital Solutions blog
  • Community LinkHCL Software forums and blogs
  • About HCL
  • Privacy
  • Accessibility