Is there a way to identify which fields in a document had been edited by the users?

Hi,

I have a document available to the users, then if some users make adjustments on the document context i want to have a log that these fields have been edited by this user.

is there a way to handle this?

thanks in advance.

pen

Subject: Is there a way to identify which fields in a document had been edited by the users?

We often use what we call ‘Audit Trails’. I did not have my own example to hand but have found the code below. The code should be placed in the ‘PostOpen’ and ‘QuerySave’ events as detailed. Replace the lines in the ‘PostOpen’ event which populate the list variable ‘old’ with the field names you wish to validate (i.e. in the example below ‘ABC’ and ‘XYZ’ are fieldnames. You also need to create a ‘History’ field on your form to hold the values being written.

There will be a nicer way to code it but this gives a good example.

(Declarations)

Dim session As NotesSession

Dim old List As String

PostOpen

Sub Postopen(Source As Notesuidocument)

Set session = New NotesSession

old(“ABC”) = Source.FieldGetText(“ABC”)

old(“XYZ”) = Source.FieldGetText(“XYZ”)

End Sub

QuerySave

Sub Querysave(Source As Notesuidocument, Continue As Variant)

On Error Goto E

Source.Refresh

On Error Goto 0

initial = Source.IsNewDoc

If initial Then m$ = session.CommonUserName & " - " & Cstr(Now()) & " - created document"

Forall F In old

v$ = Source.FieldGetText(Listtag(F))

If Not initial And Not v$ = F Then

If m$ = “” Then

m$ = session.CommonUserName & " - " & Cstr(Now()) & " - modified "

Else

m$ = m$ & ", "

End If

If F = “” Then F = {“”}

m$ = m$ & Listtag(F) & " from " & F & " to " & v$

End If

F = v$

End Forall

If initial Then

Source.FieldSetText “History”, m$

Elseif Not m$ = “” Then

Source.FieldAppendText “History”, Chr$(10) & m$

End If

X: Exit Sub

E: Continue = False

Resume X

End Sub

Subject: RE: Is there a way to identify which fields in a document had been edited by the users?

That works well for a small, known list of items you need to monitor.

For the General case where you need to track every field on a document, there’s a (complex) alternative.

Note : This won’t work for Rich Text Fields.

In the QuerySave event

If this is a new, unsaved document, then exit. (It’s not being “changed”)

Get the UNID of the current document.
(I’ll call this OpenDoc)

Get a copy of the saved document, as a NotesDocument, using notesDatabase.GetDocumentByUNID
(I’ll call this SavedDoc)

Iterate through all items of SavedDoc, and compare with OpenDoc - record any differences.

Options - Iterate through all items of OpenDoc, and compare with SavedDoc - record any new fields.

Subject: RE: Is there a way to identify which fields in a document had been edited by the users?

Thanks for your replies!..I have now an idea how to do it…

It’s more or less 50 fields in a form that ill have to check if it has been edited.

Again thanks,

pen

Subject: Is there a way to identify which fields in a document had been edited by the users?

There are ways around this as has already been suggested. However, I wish Lotus had a document property IsDocumentDirty and also a field level property IsFieldDirty. It would make life sooooo much easier. Also what would be a real plus would be a PreviousValue property on a field so that you could easily determine not only that it was changed, but from what - to what.

These properties are pretty standard stuff in a lot of other systems so it would be great to see them included in a really great system like Notes/Domino. It would make a lot of stuff a lot easier (without having to re-invent the wheel all the time).