I found some Lotus Script (below) that allows a user to select two documents in a database and then run the action that displays the fields that are different and the contents of those fields. Can anyone tell me how to modify this script to only compare specific fields - not all fields in the document? It works great but is selecting many fields when comparing that are not needed. All help appreciated.
Sub Initialize
Set session = New notessession
Set db = session.currentdatabase
Set coll = db.unprocesseddocuments
If coll.count<>2 Then
Print "Please select 2 documents"
Else
Set winner=coll.getfirstdocument
Set loser = coll.getnextdocument(winner)
'Check all fields - winner and sort into alphabetical order
fill_item_arrays winner,winneritems
sort_items winneritems
'Check all fields - loser and sort into alphabetical order
fill_item_arrays loser,loseritems
sort_items loseritems
'Combined both field lists into one and then check if equivalent
combine winneritems,loseritems,combineditems
For x = 0 To Ubound(combineditems)
processitem combineditems(x)
Next x
'Create document and report back to user
Set doc = db.createdocument()
filldocumentproperties winner,loser
writereport combineditems
End If
End Sub
Subject: more code
Hi!
To change the code, i need more (the whole) code of this script. Send it or post it and i will have a look for this.
LG Michael
http://www.notes.at
Subject: RE: more code
I am getting closer. I entered the code below based on an example sent to me and when executed I get the error message “You must provide an item name”.
=====================================
Sub fill_item_arrays(doc As notesdocument,arr() As itemrecord)
Const Fields_Of_Interest = "| Field1 | Field2 |"
Redim arr(Ubound(doc.items))
x=0
Forall i In doc.items
If Instr (Fields_Of_Interest, { | } & Lcase (i.Name) & { | } ) Then
arr(x).name=i.name
arr(x).type=i.type
x=x+1
End If
End Forall
End Sub
Subject: RE: more code
comments this pen.
Sub fill_item_arrays(doc As notesdocument,arr() As itemrecord)
Const Fields_Of_Interest = "| Field1 | Field2 |"
Redim arr(Ubound(doc.items))
x=0
Forall i In doc.items
If Instr (Fields_Of_Interest, { | } & Lcase (i.Name) & { | } ) Then
Spaces do count when doing string comparisons. Fields_Of_Interest does not contain spaces at the beginning or end, so you can never match the first or last fields. Also, you used lcase here, which assumes the field names in Fields_Of_Interest are going to be lowercase to make a match.
arr(x).name=i.name
arr(x).type=i.type
x=x+1
End If
End Forall
Redim arr(0 to x-1) ' don't include blank elements.
End Sub
Note: this code doesn’t handle the case of none of the listed items being present. Choose your fields carefully to make sure this doesn’t happen, or add error handling to notify the user when this is the case.
For future reference, if you get an error please use the LotusScript debugger to find out exactly what line it’s on. See tips for debugging and how to ask questions for more debugging information.
Subject: RE: Script Question About Comparing Fields In 2 Documents
Const FIELDS_OF_INTEREST = “|name1|name2|name3|name4|”
In the fill_item_arrays subroutine, there is probably a loop that begins Forall xyz In doc.Items, or something similar. At some later point there’s an End Forall. Or something similar. You would change this to:
Forall xyz In doc.Items
If Instr(FIELDS_OF_INTEREST, {|} & Lcase(xyz.Name) & {|}) Then
End If
End Forall