Manage Learn to apply best practices and optimize your operations.

Determining If There Has Been A Change On A Document

Here is a Lotusscript method for determining if a change has been made on a
document. The basic concept is that at specific points (Open, Edit, Save,
etc.) the values of all items on a document are captured into a global list.
Then when saving the document a comparison of the previously captured items and
values can be made with the current document items and values in order to
determine what has changed. Originally I had implemented this using dynamic
arrays to hold the item names and values... then I discovered that Lists were
much more efficient and reduced the amount of code and processing time
**Add the following line to the forms Global (Declarations)
Public ItemValues List as string

**The next step is to add code to record the initial item values.
**(1) When the form is first opened in the forms PostOpen event...
Call RecordItemValues(Source)
**(2) When the form is switched from Read to Edit in the QueryModeChange
Call RecordItemValues(Source)
**(3) And when the form is saved at the end of the QuerySave event...
Call RecordItemValues(Source)
**(This handles the case of someone performing a save and continuing to work on
the form without closing it)

**The final step is to call a routine that checks for a change in the QuerySave
event of the form...

if DocHasChanged(Source) then
' further change handling
end if

**IMPORTANT NOTE: Make sure that you call the DocHasChanged routine before
calling the RecordItemValues routine as mentioned above in step (3).

**Here is the routine that captures the items and values...

Sub RecordItemValues(Source As NotesUIDocument)

' Record the current values of all items on the document.
Dim doc As NotesDocument
Set doc = source.Document

Forall i In doc.items
itemValues(Ucase(i.Name)) = i.Text
End Forall

End Sub

** Here is the code that makes the comparison and determination that anything
has changed...

Function DocHasChanged(Source As NotesUIDocument) As Integer

Dim doc As NotesDocument
Set doc = Source.Document

DocHasChanged = False

' Catch the 'List Item Does Not Exist' Error (In case a new item was added
to the document)
On Error 120 Goto newitem

If Not source.IsNewDoc Then ' Don't check new documents
' Step through each item on the document
Forall i In doc.items
nm$ = Ucase(
If nm$ <> "$REVISIONS" And nm$ <> "$UPDATEDBY" And nm$ <>
"SAVEOPTIONS" Then ' Filter out specific fields
vl$ = itemValues(nm$)
If vl$ <> i.Text Then
' We have a change.
DocHasChanged = True
' In this case we want to report the change and stop...
you could just as easily replace the
two ' lines below with
other processing code such as recording the changes to a history field, etc.
Msgbox "Change.... Field: " & nm$ & " From:" & vl$ &
" To: " & i.Text & "."
Exit Forall
End If
End If
End Forall
End If

Exit Function

' This item is new
vl$ = ""
Resume Next

End Function

This was last published in November 2000

Dig Deeper on Domino Resources - Part 3

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.




  • iSeries tutorials's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...