1

I have a audit trail that records two fields. I just want to ask if its possible to save changes in audit trail while on read mode? My code doesn't record anything while on read mode. Can you help me guys? Here's my code:

Querysave:

Sub Querysave(Source As Notesuidocument, Continue As Variant)
    initial = Source.IsNewDoc
    If initial Then m$ = session.CommonUserName & " - " & Cstr(Now()) & " - Document Created"

    Forall F In old
        v$ = Source.FieldGetText(Listtag(F))
        If Not initial And Not v$ = F Then
            If m$ = "" Then
                m$ = session.CommonUserName & " - " & Cstr(Now()) & " - Modified "
            Else
                m$ = m$ & ", "
            End If
            If F = "" Then F = {""}
            m$ = m$ & Listtag(F) & " from " & F & " to " & v$
        End If
        F = v$
    End Forall

    If initial Then
        Source.FieldSetText "History", m$
    Elseif Not m$ = "" Then
        Source.FieldAppendText "History", Chr$(10) & m$
    End If

    X: Exit Sub

    E: Continue = False
    Resume X
End Sub

Postopen:

Sub Postopen(Source As Notesuidocument)
    Set session = New NotesSession
    old("DocName") = Source.FieldGetText("DocName")
    old("DocStatus") = Source.FieldGetText("DocStatus")

    'Disable edit in double click
    Set uidoc = source
    Set doc = uidoc.Document
    doc.mc = 1
    End 
End Sub
Anders Lindahl
  • 41,582
  • 9
  • 89
  • 93
drayl
  • 261
  • 2
  • 8
  • 21

2 Answers2

3

Whenever you need to use variables/objects between events and do not want to pollute the document with temporary values, use global variables for everything.

On postOpen the document is presumably in read mode, any changes you make to fields on the backend document (ie uidoc.document) during this event while the document is in read mode will not "stick" because you're writing to an object that is currently in read-mode. That "old" list variable is global (?), instead of trying to write to the "history" field, setup your "History" variable as a global string variable, don't try and write it to the document during postopen. When QuerySave event triggers write the global "history" string variable onto the history field on the document.

angryITguy
  • 9,332
  • 8
  • 54
  • 82
0

The best way (in my opinion) to create a history/audit trail when documents are saved is to put that code in the PostSave event, using backend classes. That code is executed after the save.

One think that I often do is declaring a global list of strings. In the PostOpen event, I populate it with values from all fields except the ones that start with $. In the PostSave (or even Terminate) event I then compare the values in that list with the current values on the document, if any value is different, I can update the document history/audit field.

Karl-Henry Martinsson
  • 2,770
  • 15
  • 25