Tracking Complete Edit History
value change, the date, user, fieldname, previous value, and new value will be
stored in the EditHistory field.
Step 1:
Create a Field on your form called EditHistory. Set it to a multi-value text
field, computed (formula = EditHistory), separate multiple values when user
enters ?;?, display separate values with New Line.
Step 2:
Declare a dynamic array in the Form (Declarations) section-
Form (Declarations)
Dim FieldValues() As String
Step 3:
Add the following code to PostModeChange. The code is placed in PostModeChange
because there is no reason to build the array of field values if the document
is not being edited. *If documents open in edit mode, place this code in
PostOpen instead of PostModeChange.
The field values are taken from the Form, not the uidocument in order to avoid
tracking hidden notes fields, such as $UpdatedBy.
Sub Postmodechange(Source As Notesuidocument)
'build array of current values
Dim session As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim form As NotesForm
Dim fieldnum As Integer
Dim counter As Integer
Set db = session.CurrentDatabase
Set doc = Source.Document
Set form = db.GetForm(doc.Form(0))
fieldnum = Ubound(form.fields)
Redim FieldValues(fieldnum,1)
counter = 0
Forall field In form.fields
FieldValues(counter,0) = field
FieldValues(counter,1) = source.fieldgettext(field)
counter = counter + 1
End Forall
End Sub
Step 4:
Add the following code to the end of QuerySave (after all edit checking is
complete).
Sub Querysave(Source As Notesuidocument, Continue As Variant)
If Not Source.IsNewDoc Then
Call EditHistory
End If
End Sub
Step 5:
Create the EditHistory sub -You can copy this code into the Form (Declarations)
section. This code adds a line to the EditHistory field for each modified
field value. The line consists of the date, user name, fieldname, prior value,
and new value (tab separated).
Sub EditHistory
Dim session As New NotesSession
Dim workspace As New NotesUIWorkspace
Dim source As NotesUIDocument
Dim fieldnum As Integer
Dim entry As String
Set source = workspace.CurrentDocument
For fieldnum = 0 To Ubound(FieldValues)
If FieldValues(fieldnum,1) <>source.fieldgettext(FieldValues(fieldnum,0)) Then
entry = Date$+Chr(9)+session.CommonUserName+Chr(9) +
FieldValues(fieldnum,0)+Chr(9)+
FieldValues(fieldnum,1)+Chr(9)+source.fieldgettext(FieldValues(fieldnum,0))
Call source.FieldAppendText("EditHistory",";"+entry)
End If
Next
End Sub