Learn how to build an audit trail feature in your HCL Notes application to track user activity, including who made changes, when the action occurred. Since HCL Notes does not offer built-in document level audit capabilities, this guide walks you through implementing a custom solution using LotusScript directly within the Notes form.
Summary Table: Benefit Description
-Accountability Tracks user actions, builds responsibility
-Security & Compliance Meets audit/compliance needs, detects violations
-Change History Tracks field-level changes over time
-Transparency Provides insight into process flow and decision points
-Troubleshooting Helps investigate issues and bugs
-Behaviour Monitoring Understands usage patterns and misuse
-Legal Evidence Defensible logs in disputes or fraud
-Data Integrity Maintains confidence in your applicationās data
Approach 1:
1.Use a Text Field for Manual Audit Trail Logging
You can create a field called āEditHistoryā and programmatically append entries each time the document is modified.
If you expect to store long logs, comments in the audit trails, or formatted content.
Field details as follows:
Field Name : Edit History
Field Type : Computed, Text
Enable the property : Allow Multiple values
Use the following sample LotusScript code in an agent .It should be triggered upon form save. This script appends a timestamped audit entry each time the document is saved or edited via a browser-based application. The resulting log will follow this format:
Example:
Document Created by < UserName> Created Time
Document Edited by < UserName> Modified Time
Sample Code :
On Error GoTo ErrorHandler
Dim sess As New NotesSession
Dim CurrentUser As New NotesName(sess.CommonUserName)
Dim HistText As String
Dim Prevtext As String
Dim strDate As Variant
Dim CurDoc As NotesDocument
Dim LoginUser As String
MsgBox āhere in editingā
Set CurDoc = sess.DocumentContext
'LoginUser = sess.UserName
LoginUser =CurrentUser.Abbreviated
PrevText = CurDoc.EditHistory(0)
If PrevText <> āā Then
HistText = PrevText + Chr$(10) + "Document Edited by ā+LoginUser+ā on "+ CStr(Now)
Else
HistText = "Document Created by " + LoginUser + " on " + CStr(Now)
End If
CurDoc.EditHistory=HistText
Note:
This method adds Summary data to the form and counts toward the documentās total allowed Summary data. If the form already includes a large amount of Summary data or if extensive post creation edits are expected, Option 2 is recommended, as the Text field in Notes has a 32 KB limit.
Approach 2:
2.Use a Separate Audit Log Document
To handle scenarios where the limit is exceeded, you may consider the following approach Instead of embedding logs in the form, you can also create a separate database or document for audit logs.
Create a new form called AuditLog.Fields: FormID, ModifiedBy, ModifiedOn, ActionTaken, FieldName, OldValue, NewValue
On each save in your primary form, use LotusScript to compare fields and create a new AuditLog document.
User below script on the PostSave event of the form.
Sample Code:
Sub Postsave(Source As Notesuidocument)
Dim session As New NotesSession
Dim db As NotesDatabase
Set db = session.CurrentDatabase
Dim doc As NotesDocument
Set doc = Source.Document ā Compare fields and write to log
Dim logDoc As NotesDocument
Set logDoc = db.CreateDocument
logDoc.Form = āAuditLogā
logDoc.FormID = doc.UniversalID
logDoc.ModifiedBy = session.CommonUserName
logDoc.ModifiedOn = Now
logDoc.ActionTaken = āEditedā
logDoc.FieldName = āSomeFieldā
logDoc.OldValue = āOld value hereā
logDoc.NewValue = doc.GetItemValue(āSomeFieldā)(0)
Call logDoc.Save(True, False)
End Sub
Disclaimer:
Please note that the testing conducted is intended as an example to guide your implementation. We recommend working closely with your development team to adapt and integrate the solution into your specific production environment. Product Support is not available for customizing solutions to fit individual customer setups. Additionally, we recommend collaborating with your Quality Assurance team to thoroughly review the test results and ensure that all relevant scenarios are adequately covered.