Record Rules - Part 1
Transcript Summary
Introduction
What's up, Databasers? Sam here, and in this video, I'm going to teach you all about record rules.
What Are Record Rules?
In the form component, you can use record rules to automate various tasks. You can:
- Update the current record.
- Update connected records.
- Insert a new record.
- Insert a connected record.
At its core, record rules are automation tools that allow you to pull in dynamic values (values that change) and save them as static values in your table.
Key Features of Record Rules
-
Dynamic to Static Value Conversion: Record rules allow you to pull in dynamic values, like dates, and save them statically in your database.
-
Automation Similarities: Record rules work similarly to other automation tools in Tadabase, like scheduled tasks, action links, and table rules. The concepts you learn here will apply to those features as well.
"Update This Record" Example
Under the "Update This Record" option, you can:
- Set a field to a custom value (e.g., set a field to a specific word).
- Set a field to blank.
- Set a field to the value of another field in the same form (called a form value).
- Set a field to a value from a connected table.
- Set a field to the logged-in user's field (e.g., user's name or email).
- Set fields to local browser storage values.
Date fields have the unique option to set to the current date and time, while number and currency fields can use arithmetic.
Example: Auto-Filling Fields in a Form
Let’s take an example where we have a form for adding inspections. The form has fields like title, description, status, added on date, and added by (who created the inspection). Rather than having the user fill out all these fields, we can automate some of them using record rules:
- Status: Always set to "Open" automatically.
- Added On: Automatically pulls in the current date and time.
- Added By: Set to the logged-in user.
When the form is submitted, the record rules automatically fill in these fields without user input.
Example: Connected Values
You can also use record rules to pull in values from connected tables. For example, if you're adding a note to an inspection, you may want to pull in the inspection status from the connected inspection record. This allows you to save the status of the inspection at the time the note was added.
Even though the status may change later, the record rule saves the current value at the time of the note creation.
Example: Logging User Data
You can use record rules to pull in data from the logged-in user. For instance, you may want to capture the proficiency level of a technician when a job is marked as completed. This allows you to track their proficiency at the time the job was finished, even if their level changes later.
Example: Using Arithmetic
Another feature of record rules is arithmetic. Let’s say you want to track how many times an inspection has been edited. You can set a rule to increment a "Total Edits" field by 1 every time the form is submitted. This way, you can track how many times a record has been modified.
Example: Setting Blank Values
You can set a field to blank based on conditions. For example, if an inspection is marked as completed, you may want to clear the due date since it's no longer relevant. Record rules allow you to automate this process by setting the due date to blank when the status changes to "Completed."
Example: Saving Form Values
You can save a value entered in one form field to another field in the same record. For example, you may have a description field that the customer fills out. Later, a technician might edit that field, but you don't want to lose the original value. You can save the original description to a separate field and keep track of both the customer’s input and the updated information.
Important Tips
-
Use One Rule When Possible: Instead of creating multiple rules, try to combine related actions into one rule to keep things efficient. Multiple rules can cause the record to update several times, which can slow things down.
-
Order of Operations: The record rule that is closest to the database (runs last) will override any earlier rules. For example, if one rule sets the status to "Open" and another sets it to "Pending," the second rule will take precedence.
-
Difference Between Record Rules and Table Rules: Record rules run when a form is submitted and are tied to the specific form. Table rules, on the other hand, apply to all records in a table and run whenever data is added or updated in the table, regardless of the form.
Conclusion
Record rules allow you to automate various tasks when submitting forms, such as setting custom values, pulling in connected data, performing arithmetic, and more. They make form submissions more efficient and can save a lot of time by automating repetitive tasks.
Thank you for watching! I hope this video helped you understand the power of record rules. Have a great day!
We'd love to hear your feedback.