Use Record Rules to Create an Audit Log
You can use record rules to create and track audits in your app.
Before we begin, we will go over what we are trying to accomplish in this demonstration.
Say you have several projects and you have users with login access to change or update the projects, you may want to create an audit log to track all updates, edits, and deletes being made to your projects.
By creating a form within the project details page we can use the form to edit the project and with the form's record rules we can create a new connected record within the audit logs page with the Auditor's details.
Now that you have a general understanding of what we're trying to accomplish let's get into the specifics:
The first step is to go into the data builder and create two data tables: Projects and Audit Logs. In the Projects Table you can add a few fields such as:
- Project Name
- Due Date
- Project Details
In the Audit Logs Table you can add:
- A text field called "Auditor Name"
- A date/time field called "Audit Occurred at."
- A connection to Projects
- A connection to Users
Now that we've built our data structure let's move on to the Page Builder to design how our data will be displayed. In the page builder, add a page with a table component and select the Projects Data Table. Then select Quick Add and choose the first three options which should consist of: a form to add projects, a details page, and a table of connected audit logs within the details page.
Now the you have created the projects and details pages, you can to go into the details page and select to add a component. You can choose a Form and select to update this page's projects and click Quick Add.
Now you can go into Form Rules, click on Record Rules and select Add New Rule. Then select to Insert Connected Record >Audit Logs and set three rules:
Set >User Name to Auto Logged User
Set >Auditor Name to Logged in User's Field of Name
Set >Audit Occurred at to Current Date and Time
Now you have created the rules necessary to track changes on your app. To test this feature on your app, first create a user by heading to the Users Tab. You'll need to be logged in to a user in order for the app to know who is making any changes.
To test your app, simply login, create a project and make an edit.
We'd love to hear your feedback.