Notes Ninjas Notes Ninjas
Lotus Notes hints, tips, error messages
Add Audit Trail to Notes Document

Hint Short Cut: Add this to your code & documentation to help you find this page.
http://www.notesninjas.com/#AuditTrail or http://www.notesninjas.com/A555F9/nn.nsf/ByAlias/AuditTrail


It can be useful to add an audit trail to a notesdocument. I usually add this to workflow type systems to record when emails were sent and statuses changed. Useful for debugging and useful to see where the bottlenecks are in a system.





Audit Trails can cause lots of replication issues as the audittrail field is changed everytime something changes, having an audit trail for each user, and then merging the history on display may solve the problem but I have never done it like that.

 

Anyway here is a load of code I keep reusing which I am storing here so I don't have to type it in all the time:

 

@function version

r:=@If(@IsDocBeingEdited="0";@Command([EditDocument];"1");"1");
@If(r="0";@Return(@Prompt([Ok];"!";"You do not have edit rights to this document!"));"");
@If(@IsValid;"";@Return(""));

FIELD Status:="Submitted";

FIELD AuditTrail:=AuditTrail:(@Text(@Now;"T1")+"  "+@Name([CN];@UserName)+"  Submitted to  " +@Name([CN];authoriser));

@If(@IsNewDoc;@Command([FileSave]);"");

@MailSend(Authoriser;"";"";Form+" "+Reference+ " needs authorising.";
@If(@Subset(@DbName;1)="";"This expense was created on a local database, so may not yet be available.";"This is available for authorising now.");"";[IncludeDoclink]);

@PostedCommand([FileSave]);

@PostedCommand([FileCloseWindow]);

""

 

Lotus Script Version

Put this in a query save or in a lotusscript button or even in a lotusscript agent.

 Dim uiw As New notesuiworkspace
Dim uidoc As notesuidocument
Dim s As New NotesSession
Dim db As notesdatabase
Set db = s.currentdatabase

Set uidoc = uiw.currentdocument
If uidoc.EditMode=False Then uidoc.editmode=True
Dim doc As notesdocument
Set doc = uidoc.Document

 ' Update Audit Trail
Dim nn As notesname
Set nn = New notesname(doc.authoriser(0) )
Dim ni As notesitem

 if doc.hasitem("AuditTrail") then
  Set ni = doc.GetFirstItem("AuditTrail")

 else

  Set ni = New notesitem(doc,"AuditTrail",Format$(Now,"dd/mm/yyyy hh:nn") & " Created")

 end if
Call ni.AppendToTextList(Format$(Now,"dd/mm/yyyy hh:nn") & " " & s.commonusername & " Submitted to " & nn.common)

Call doc.replaceitemvalue("Status","Submitted")
Call uidoc.Reload
Call uidoc.Save()
Set doc =uidoc.document ' reload document

 'Send an email with doclink - make sure to save first
Dim mdoc As New notesdocument(db)
mdoc.subject=doc.form(0) & " " & " needs authorising."
Dim rt As New notesrichtextitem(mdoc,"Body")
Call rt.AppendText("Please authorise this document: " )
Call rt.AppendDocLink(doc,"DocLink" )
Call rt.AddNewline(1)
If db.Server="" Then
 Call rt.appendtext("NB This document was created on a local replica, and so may  not be available yet.")
Else
 Set nn=New notesname(db.server)
 Call rt.appendtext("This document is on server: " & nn.abbreviated & "  path: " & db.filepath)
End If
Call mdoc.send(False,doc.authoriser(0) )
Call uidoc.Close

 

NB:

 format$(Now,"dd/mm/yyyy hh:nn")  

is the same as

 @Text(@Now;"T1")

which basically makes the time 254 hour , 4 digit year and without seconds.

 

 Jump to:     Notes Tips
    Lotus Notes Index 
  Register for Tips
Previous Lotus Notes Tip 
    Next Lotus Notes Tip
Your company logo here?
Adam Foster
Free Cash Making Web Site
Free Revenue Earning Blog Site
 Free Revenue Earning Newsletter Site   
Free Search Pages Free Web stats
Free Contact Us page
Cheap .com domain names
 Need a website or 
   Lotus Notes
  problem solved?
Adam Foster
Web Services Platform Architecture: Soap, WSDL, WS-Policy, WS-Addressing, WS-Bpel, WS-Reliable Messaging and More by Francisco Curbera, Frank Leymann, Tony Storey, Donald Ferguson, Sanjiva Weerawarana
Other books claim to present the complete Web services platform architecture, but this is the first one I've seen that really does. The authors have been intimately involved in the creation of the architecture. Who better to write this book?
See at: Amazon.co.uk | Amazon.com |