Auditing

jdpjamesp

ProgressTalk.com Moderator
Staff member
Currently for auditing purposes inside triggers, we go through a list of auditable fields and manually check their value against the old buffer, then add them to a chr(1) delimited list to create the audit records.

I'm trying to come up with a solution the uses the BUFFER-COMPARE statement to generate a list of the fields that have changed and then use buffer handles to store the different values. The problem is of course, that as soon as you use buffer handles, you get the same (new) result from the new buffer and the old buffer.

Does anyone have a solution to this problem?

Code snippet:

Code:
DO lvi = 1 TO NUM-ENTRIES(lvDiffs):
  ASSIGN
    lvLabels    = lvLabels +
                  (IF lvLabels EQ "" THEN "" ELSE CHR(1)) +
                  ENTRY(lvi,lvDiffs)
    lvOldValues = lvOldValues +
                  (IF lvOldValues EQ "" THEN "" ELSE CHR(1)) +
                  STRING(lvOldHandle:BUFFER-FIELD(ENTRY(lvi,lvDiffs)):BUFFER-VALUE)
    lvNewValues = lvNewValues +
                  (IF lvNewValues EQ "" THEN "" ELSE CHR(1)) +
                  STRING(lvNewHandle:BUFFER-FIELD(ENTRY(lvi,lvDiffs)):BUFFER-VALUE).
END.
 
Why don't you use a temp-table to store the old values and then do a buffer-compare between the new buffer and the temp-table buffer?
 
Thanks palthe - I just had that idea last night myself. I will give it a go later today and report back how it goes.
 
I'm a div! I was using the wrong variable. The original method does work, no tt required.

The problem was:

Code:
IF lvLabels NE "" OR lvOldValues NE "" OR lvNewValues NE "" THEN
DO TRANSACTION:
  CREATE Audit.
  ASSIGN
    Audit.Entity    = lvEntity
    Audit.LABELS    = lvLabels
    Audit.NewValues = lvNewValues
    Audit.OldValues = [B]lvNewValues[/B]
    Audit.SOURCE    = lvSource
    Audit.AuditDate = TODAY
    Audit.AuditTime = TIME
    Audit.AuditType = lvType.
END.

Spot the error :confused:
 
Back
Top