LCS - Using the Compare Record action function

The Compare Record function allows a developer to easily get the changes that have occurred in a record, usually from an update form action. This can be useful for Audit logs and detecting if record fields were updated.

Version History

1.0 - initial release support comparing two of the same models for changes, allows for the exclusion of fields, debug logging and JSON or text output.

Usage

The most common use case for this action step will be to determine changes made to a record being returned from an update form. This KB will walk through how to set that up. 

Form setup

Due to a bug in action variables to access the original version of the record in the action we must add a hidden field to the form that has the value of the records ID. 

Action setup

Then in the Start section of the action go to the Action Variables tab and create a new Record variable. For the model, select the model that is being passed into the action. Add a filter for the id of the model equal to the input variable id that we made via the hidden input in the last step. Apply the filter and save the action variable. Next save the updated record like normal in an update action.

image of edit variable tab to create new record

Function Setup & Configuration

If you haven’t already installed the block from the block store do so now. With the block installed drag the action step, located in MISC section, onto the canvas below the update record step. 

The action step will have 3 required inputs and 3 optional inputs.

image of compare records options

Required

  • The updated record - this is where we will select the output of the Update Record step
  • The original record - this is where we will select the action variable we created
  • Result - this will capture the comparison result and return it back to the action as text

Optional

  • Excluded properties - by default we have added the updated_at and created_at fields. If there are other fields to exclude you can do it here.
  • Output as Object - select this option if getting the result as stringified JSON is what you want for further processing of comparison result.
  • Debug logging - to see the raw results of the comparison turn on debugging and the function will output the results to the application logs.

Saving it to a record

With the difference now in an output text variable, it's easy to store that in an audit log record or any other record property that the application might call for.



Keywords:
Audit, diff, logging, action step, functions, block 
Doc ID:
139036
Owned by:
Joel H. in Low Code Solutions
Created:
2024-08-09
Updated:
2024-11-14
Sites:
DoIT Enterprise Business Systems - Low Code Solutions