Tuesday, July 17, 2007

SIMPLE AUDIT TRAIL USING @FORMULA

Formula based design to capture audit trail for notes field values. No lotus script program required and no need to modify the save event programs.

Create the following fields and add the formulas


Audit_CurrentValue - Hidden field to store field name configuration
var1:="Employee Name":"Employee Number":"Department":"Designation";
var2:=EmpName:@Text(EmpNumber):EmpDept:EmpDesg;
var1+"="+var2


Audit_ChangedValue - Hidden field to identify changed values
tChanges := @If(@IsNewDoc;"";@Replace(Audit_OldValue;Audit_CurrentValue;""));
@Trim(tChanges)

Audit_OldValue - Hidden field to store old field values
@If(@IsDocBeingSaved;Audit_CurrentValue;Audit_OldValue)

Audit_History - Field to display audit history
hisDateTime:=@Text(@Now) + " (" + @Text(@Name([CN]; @V3UserName)) + ")";
@If(@IsDocBeingSaved;Audit_History:@If(Audit_ChangedValue!="";hisDateTime;""):@Implode(Audit_ChangedValue;",");Audit_History)

Sample Output:
07/16/2007 03:46:47 PM (User name)
Employee Number=2000,Designation=Consultant
07/16/2007 04:01:46 PM (User name)
Employee Number=3000,Department=Lotus Notes Development,Designation=Programmer

You can also display both new value and old value
Change the formula of Audid_ChangedValue to

tChanges:= @Trim(@If(@IsNewDoc;"";@Replace(Audit_OldValue;Audit_CurrentValue;"")));
@If(tChanges="";"";@Transform(tChanges;"X1";X1+"->"+@Right(Audit_CurrentValue[@Member(X1;Audit_OldValue)];"=")))


Sample output:
07/16/2007 04:07:21 PM (User name)
Department=Lotus Notes->Lotus Domino,Designation=Programmer->Developer
07/16/2007 04:07:40 PM (User name)
Employee Name=Manny->Manikandan

3 comments:

rajjo said...

Hi Manny,
It really reduces the lines of codes but it can have only the last made changes right? I don't think this audit trail will hold all the changes made in the document like a rich text field does

Manny said...

Hi Raji,

To capture audit trail for all fields, this formula based code is not recommended. Its better to write the audit trail functionality in lotus script and use RICHTEXT Field to store the audit trail history.

- Manny

Marysunshine said...

Thanks dear!
There are times when we tend to forgot the simplest solution.