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.