Creating an Effective Audit Subrecord

By Chris Malek | Tue, Jan 24, 2012

Here is a simple but invaluable audit subrecord that I like to put on all my records. It logs when the row was originally created and by who and when the row was last updated and by whom. This can be invaluable for debugging issues and doing research on data. You just need to put this sub-record on all your records and the code will fire automatically to set the audit fields.

Sub-Record Name: C_AUDIT

Field NameUsageField Type
LASTUPDDTTMThe last date-time the row was updated.DateTime
LASTUPDOPRIDThe last user who updated the row.Char(30)
C_CREATED_TIMEThe date-time the row was created.DateTime
C_CREATED_USERThe user who created the row.Char(30)

The subrecord has one piece of Peoplecode on LASTUPDDTTM.SavePreChange

If GetRow().IsNew And
      GetRow().IsChanged Then
   GetRecord().C_CREATED_TIME.Value = %Datetime;
   GetRecord().C_CREATED_USER.Value = %OperatorId;
   GetRecord().LASTUPDDTTM.Value = %Datetime;
   GetRecord().LASTUPDOPRID.Value = %OperatorId;
Else

   If GetRow().IsChanged Then
      GetRecord().LASTUPDDTTM.Value = %Datetime;
      GetRecord().LASTUPDOPRID.Value = %OperatorId;
   End-If;

End-If;
Article Categories
Author Info
Chris Malek

Chris Malek is a PeopleTools® Technical Consultant with two decades of experience working on PeopleSoft enterprise software projects. He is available for consulting engagements.

About Chris Work with Chris
Looking for pain-free PeopleSoft web services? 😀
PeopleSoft Simple Web Services (SWS)

Introducing a small but powerful PeopleSoft bolt-on that makes web services very easy. If you have a SQL statement, you can turn that into a web service in PeopleSoft in a few minutes.

Book
Integration Broker - The Missing Manual

I am in the process of writing a book called "Integration Broker - The Missing Manual" that you can read online.