Skip to main content link. Accesskey S
  • Anonymous
  • Log on
  • Help
  • IBM logo
  • Lotus Notes and Domino Application Development wiki
  • All Wikis
  • Home
  • Community Articles
  • Product Documentation
  • Learning Center


Search

Advanced Search

Categories

Tag Cloud

  • 6.0
  • 6.5
  • 8.0
  • 8.5
  • 8.5.1
  • 8.5.2
  • 8.5.3
  • action bar
  • Agents
  • Ajax
  • app dev
  • Application
  • beginner
  • C&S
  • calendaring and scheduling
  • client
  • composite applications
  • Controls
  • converters
  • css
  • Custom controls
  • Data Binding
  • db2
  • design elements
  • dialog boxes
  • Documents
  • Dojo
  • Domino
  • Domino Designer
  • Domino Designer 8.5
  • DXL
  • Eclipse
  • error handling
  • errors
  • extensions
  • FAQ
  • Forms
  • formulas
  • getting started
  • globalization
  • Help
  • html
  • Installation
  • interface
  • internationalization
  • iPhone
  • Java
  • JavaScript
  • localization
  • Lotus Domino Designer
  • LotusScript
  • LotusSphere
  • LotusTechInfo
  • menu bar
  • Mobile
  • new user
  • Notes
  • Notes 8
  • notes.ini
  • NSD
  • OpenNTF
  • partial update
  • performance
  • Pickers
  • Portal
  • presentations
  • programming
  • Redbooks
  • Requested Articles
  • roadmap
  • rooms and resources
  • samples
  • Scripting
  • security
  • tabs
  • templates
  • themes
  • Tips
  • toolbar
  • troubleshooting
  • tutorials
  • validation
  • variables
  • video
  • VideoFest
  • View
  • view control
  • ViewPanel
  • Views
  • web
  • Web apps
  • Web services
  • webdev
  • XML
  • Xpage
  • XPages
  • XPages Extensibility API
  • xsp-config
  • データソース
  • 九州地区ノーツパートナー会
InformationInformation
You are currently viewing machine translated content. IBM translation might be available. Click IBM Translated Product Documentation to see what is available.X


Home > Troubleshooting > LotusScript function to compare the items of two documents
Rate this article 1 starRate this article 2 starsRate this article 3 starsRate this article 4 starsRate this article 5 stars

LotusScript function to compare the items of two documents 

expanded Abstract
collapsed Abstract
No abstract provided.

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/blog


expanded Article information
collapsed Article information
Category:
Troubleshooting
Tags:
Troubleshooting Conflicts Compare NotesDocument NotesItem Item

This Version: Version 5 March 3, 2010 8:46:47 AM by Marcus MF Foerster  

expanded Attachments (0)
collapsed Attachments (0)

 


expanded Versions (5)
collapsed Versions (5)
Version Comparison     
Version Date Changed by               Summary of changes
This version (5) Mar 3, 2010 8:46:47 AM Marcus MF Foerster  
4 Mar 3, 2010 8:44:55 AM Marcus MF Foerster  
3 Mar 3, 2010 8:44:27 AM Marcus MF Foerster  
2 Mar 3, 2010 8:42:08 AM Marcus MF Foerster  
1 Mar 3, 2010 8:39:37 AM Marcus MF Foerster  
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 ConnectedSubscribe to RSSHelpAbout
  • All Lotus and WebSphere Portal wikis
  • IBM developerWorks
  • IBM Software support
  • IBM Social Business User Experience Blog
  • IBMSocialBizUX on Twitter
  • IBMSocialBizUX on Facebook
  • Lotus product forums
  • IBM Social Business UX blog
  • IBM Collaboration Solutions
  • Recently added feedRecently added
  • Recently edited feedRecently edited
  • Recently added comments feedRecently Added Comments
  • Wiki Help
  • Forgot user name/password
  • Wiki design feedback
  • Content feedback
  • About the wiki
  • About IBM
  • Privacy
  • Contact IBM
  • IBM Terms of use
  • Wiki terms of use