Auto populate CREATE/UPDATE USER_ID and CREATE/UPDATE DT on inserting/updating a record

Almost every Codecharge form needs to auto populate create and update audit fields. Here is how it can be done.

CREATE_USER_ID

Steps

  1. Before Insert (Record) Event
  2. Add Action - “Retrieve Value for Control” & Set
    1. Control Name = CREATE_USER_ID
    2. Source Type = Session
    3. Source Name = UserLogin

CREATE_DT

Steps

  1. (Add another) Before Insert (Record) Event
  2. Add Action - “Retrieve Value for Control” & Set
    1. Control Name = CREATE_DT
    2. Source Type = Expression
    3. Source Name = time()

UPDATE_USER_ID

Steps

  1. Before Update (Record) Event
  2. Add Action - “Retrieve Value for Control” & Set
    1. Control Name = UPDATE_USER_ID
    2. Source Type = Session
    3. Source Name = UserLogin

UPDATE_DT

Steps

  1. (Add another) Before Update (Record) Event
  2. Add Action - “Retrieve Value for Control” & Set
    1. Control Name = UPDATE_DT
    2. Source Type = Expression
    3. Source Name = time()

Formatting

Set both CREATE and UPDATE date to the following date format to display the full date with time

mm/dd/yyyy h:nn:ss AM/PM

And to the following for the dbformat

yyyy-mm-dd HH:nn:ss

Other consideraions

  • Make all create userid/date NOT required
  • Make all create/update userid/date read-only
  • Make all field the same size and remove any blank spaces around the controls. Size 20 seems to work well.
  • Appreance
    • Group all audit fields in one row with four columns
    • Delete the date pickers
    • Add a blank row about the four column row and label it with “{res:audit_field_div}”
    • Update the Locale for the above as “Create User/Date & Update User/Date”

Alternate way to auto populate CREATE_USER_ID and CREATE_DT on new record

This method should not be used because it does not set the insert date on the time of insertion. It sets it when the blank record is loaded and the date will not be accurate. The User id on the other hand is fine.

CREATE_USER_ID

In the default value property

 CCGetSession("UserLogin") 

CREATE_DATE

In the default value property

 CurrentDateTime 

QR Code
QR Code tech:codecharge:setting_audit_columns (generated for current page)