Manage Learn to apply best practices and optimize your operations.

General Purpose Audit Trail Script

This set of scripts will record any changes to any fields in a given form. It
will record the date/time, Person making the change, old value of the field(s)
changed, New Value of the fields.

The script requires you create an audit trail form and view, then insert the
scripts into various form events.

Also, you must decide on a "key-field" in the form you are auditing. it should
be unique and enough to identify the document in the audit trail documents.
This needs to be done in the QueryClose event of the form you're auditing. In
the code, look for the area;

If Len(Updates) Then
key=uidoc.FieldGetText("Key")
dt=Now
Updater=session.username
End If

Change "Key" to whatever the name of the field in your form you're going to
consider being the keyfield.

The only problem with this script is that if a person tries to save a form but
is stopped because of a verification check, then decides to quit out of the
form, it will save an audit event anyway. Any suggestions in this area are
welcome.

I would image you will also want to write an agent that trims the audit trail
every so often.
Form: AuditTrail
Type: Document
Field: KeyField
Datatype: Text
Field Type: Computed
Formula: Keyfield

Field: Updater
Datatype: Names
Field Type: Computed
Formula: @Name([CN]; Updater);

Field: Date
Datatype: Time
Field Type: Computed
Formula: Date

Field: Updates
Datatype: Text
Field Type: Computed
Formula: Updates
+++++++++++++++++++++++++++++++++++++++++++++++++
View Name: Audit Trail
Selection Formula: SELECT Form = "AuditTrail";

Column Number: 1
Column Title: Key Field
Column Formula: KeyField
Column Width: 10 Characters

Column Number: 2
Column Title: Date
Column Formula: Date
Column Width: 12 Characters

Column Number: 3
Column Title: Updater
Column Formula: @Name([CN]; Updater);
Column Width: 16 Characters
Hide Detail Values: No

+++++++++++++++++++++++++++++++++++++++++++++++++

In the form you wish to audit, place the following in the form's events.

Define: (Globals) {Form you want to monitor}
Event: Declarations

Dim FieldNames
Dim FieldValues
Dim WasSaved As Integer
Dim NewDoc As Integer

Define: {Form you want to monitor} (Form)
Event: PostOpen

Sub Postopen(Source As Notesuidocument)
Dim WorkSpace As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Set uidoc = Workspace.CurrentDocument
WasSaved=0
i=Ubound(uidoc.document.items)
If uidoc.IsNewDoc Then NewDoc=1 Else NewDoc=0
Redim fieldnames(i)
Redim fieldvalues(i)
i = 0
If Not uidoc.isnewdoc Then
Forall item In uidoc.document.items
fieldnames(i)=item.name
fieldvalues(i)=item.text
i = i + 1
End Forall
End If
End Sub

Define: {Form you want to audit} (Form)
Event: QuerySave

Sub Querysave(Source As Notesuidocument, Continue As Variant)
WasSaved=1
End Sub

Define {Form you want to audit} (Form)
Event: QueryClose

Sub Queryclose(Source As Notesuidocument, Continue As Variant)
Dim WorkSpace As New NotesUIWorkspace
Dim db As NotesDatabase
Dim session As New notesSession
Dim uidoc As NotesUIDocument
Dim doc As NotesDocument
Dim Key As String
Dim Updater As String
Dim dt As String
Dim Updates As String
Set db = session.CurrentDatabase
Set doc = New NotesDocument(db)
Set uidoc = Workspace.CurrentDocument
If NewDoc=0 Then
Forall item In uidoc.document.items
For i = 1 To Ubound(FieldNames)
If Not FieldNames(i)="$Revisions" Then
If item.name=FieldNames(i) Then
If Not fieldvalues(i)=item.text Then
Updates=Updates+Chr$(13)+item.name+" Old =
"+FieldValues(i)+" New = "+item.text
End If
End If
End If
Next
End Forall
Else
Updates="New Document"
End If
If Len(Updates) Then
key=uidoc.FieldGetText("Key")
dt=Now
Updater=session.username
End If
Set db = session.CurrentDatabase
Set doc = New NotesDocument(db)
doc.form="AuditTrail"
doc.Keyfield=key
doc.Updater=Updater
doc.Date=dt
doc.Updates=Updates
If WasSaved=1 Then Call doc.save(True, False)
End Sub

That's all folks!

Dig Deeper on Domino Resources - Part 7

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchWindowsServer

Search400

  • iSeries tutorials

    Search400.com'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 ...

SearchDataCenter

SearchContentManagement

Close