Table Audit Trail

  

Good day,


Can Anyone help me?

I have a contacts table, and everytime I update one of it's feilds, I want an audit trail record.

for example I want to edit the contact name from Abel Pasquale to Abel  Babel. then I want to have an audit trail records for the fields I edited.

Thanks in advanced

Hi Daryl.

I would say to follow an approach similar to this:

  • If you already have your own create or update action, do the logic inside it. If not, create an action to enclose the logic needed to create or update your entity - this way all the business logic can be only at one place and will allow you to reuse it anywhere you want.
  • Inside that action, anytime you create or update your entity, you should call the audit action with the information you need to audit. 
    • You can log all the information for instance in json before and after the update or simply use an action to check the differences between the two records and only log something like "In the record X changed the name from Jonh to Jonh Snow".

Hope it helps.

Cheers,

GM

Gonçalo Martins wrote:

Hi Daryl.

I would say to follow an approach similar to this:

  • If you already have your own create or update action, do the logic inside it. If not, create an action to enclose the logic needed to create or update your entity - this way all the business logic can be only at one place and will allow you to reuse it anywhere you want.
  • Inside that action, anytime you create or update your entity, you should call the audit action with the information you need to audit. 
    • You can log all the information for instance in json before and after the update or simply use an action to check the differences between the two records and only log something like "In the record X changed the name from Jonh to Jonh Snow".

Hope it helps.

Cheers,

GM


Thanks, I'll try to o that now. 

Gonçalo Martins wrote:

Hi Daryl.

I would say to follow an approach similar to this:

  • If you already have your own create or update action, do the logic inside it. If not, create an action to enclose the logic needed to create or update your entity - this way all the business logic can be only at one place and will allow you to reuse it anywhere you want.
  • Inside that action, anytime you create or update your entity, you should call the audit action with the information you need to audit. 
    • You can log all the information for instance in json before and after the update or simply use an action to check the differences between the two records and only log something like "In the record X changed the name from Jonh to Jonh Snow".

Hope it helps.

Cheers,

GM


Do you have a sample oml for that? thanks

Hi Daryl,

You can use the Human Readable Change History component to get the changes made to the entity in a description style text. 

Hope this helps.

CA

Carlos Alfaro wrote:

Hi Daryl,

You can use the Human Readable Change History component to get the changes made to the entity in a description style text. 

Hope this helps.

CA


Thank carlos, I will check it now.

You can do something like this, as the Create or update method to reuse and centralize all your business rules:



But for your purpose, if you don't want to save a JSON with all the info, use definitely the forge component that @Carlos mentioned because it will save you a lot of conditions and you'll get a better performance.