Table of Contents
- What are Record Rules?
- Manage Record Rules
Updated by Danielle Kellogg
- What are Record Rules?
- Manage Record Rules
What are Record Rules?
Record rules are a type of rule, which allow you to automate specific actions behind-the-scenes when a form is submitted or a table is edited inline in the Live App.
These rules can:
- Update the record the view is using
- Update connected records
- Insert new connected records
Here are some common examples of what you can do with record rules:
- Track which user created or last updated a record
- Track the date and time a record was created or last updated
- Create a new receipt record when an order is submitted
- Change a record status when a field value is changed
Manage Record Rules
Record rules are available on form views and table views while inline editing. To add, edit or delete record rules, you will first need to either add a new form or table, edit an existing form view or enable inline editing on a table.
Add a Record Rule
To add a record rule to your app, navigate to the "Pages" section of your Knack Builder, and select the form or table view to open the view editor.
Add a Record Rule to a Form
Once the view editor is open, select "Rules" from the left toolbar, and then select the “Record Rules” section.
Once on the "Record Rules" tab in the view editor, you can select “Add Rule” and you have added your first record rule.
Now that you have added a record rule, you can define what it does. This is done by defining the action that will be triggered, when it will run, and which values the rule updates. You can read more on record rules settings below.
Add a Record Rule to a Table
Inline editing will need to be enabled before record rules can be added to a table view. You can enabled inline editing from the settings section of the view editor.
Once inline editing is enabled, record rules can be added to specific table columns by editing the column properties.
Edit a Record Rule
Similar to accessing a form to add record rules, to edit an existing record rule, locate the form the rule is on in your Builder and open the view editor. Next select “Form Rules” and then select “Record Rules”. There any record rule settings can be edited for existing rules.
Delete a Record Rule
When editing the record rules on a form view, you can delete existing record rules by clicking the trashcan icon in the top right corner of the rule.
Copy a Record Rules
When editing the record rules on a form view, you can copy existing record rules by clicking the duplicate icon in the top right corner of the rule.
Move a Record Rule
When editing the record rules you can rearrange the rules, this can be helpful in managing a multiple record rules.
Record Rule Settings
Actions: What can Record Rules do?
The first setting in a record rule is called an "Action." This defines what Knack will do behind the scenes once the form has been submitted.
There are three action options:
- Update this record
- Insert a connected record
- Update a connected record
Update this record
This option will update the primary record the form is working with. This is useful for setting status or workflow fields on submission. You can also assign logged-in users so you can track who submitted a comment, rating, or ranking forms.
- Assign the logged-in user to the object’s Created by field (a connection to a user role) so that you have a record of which user added the form.
- Assign the Submitted late? yes/no field the value of Yes when the form was submitted after a Due date field.
See these guides for using record rules to track what user updated records and when.
Update connected records
This option allows you to update records connected to the form's record. When adding this record rule type you will be able to select which connected object to insert a record into. Your form’s object must be connected to at least one other object for this option to be available.
For example, when a Line Item in an Order is changed, a record rule on the “Update Line Item” form can update the connected Order record’s “Last Updated” field.
Insert a connected record
This option adds a new record connected to the form’s record. When adding this record rule type you will be able to select which connected object to insert a record into. Your form’s object must be connected to at least one other object for this option to be available.
This is great for adding new notes to a project or creating a version history of records that can be accessed in the Live App.
For example, upon submitting a form which edits a record, insert a new connected record of the same object with all of the same data, where the connection is called Record history entry. This way, you can track each change to the parent record with a separate record.
You can read more on using record rules to set up a record history here.
When: When will a Record Rule run?
The "When" section of the record rule defines the condition that needs to be met to trigger the rule. When a form is submitted and all the conditions are met, the rule will run.
By default the rule is set to run for every form submission. You can add criteria based on one or more specific form values.
For example with a Task record, you may want to indicate whether it was completed on time. You can add When qualified to assign the Submitted late? yes/no field the value of Yes when:
- The status is Complete
- The current date is after the Due Date on the Task
Values: What will a Record Rule update?
The "Values" section of the record rules is where you set the field values that the rule will apply. Here you can add multiple value settings by selecting the green “+” button, or remove the settings by selecting the red “-” button.
Values can be set to:
- A connected value: choose a field from a record connected to the form record. You can only set a connection field’s value based on another connection value - it cannot be set to a name or auto-increment (ID) field.
- A custom value: This allows you to either:
- Enter a value manually.
- Or you can append or remove values for multiple choice fields or connection fields without overwriting the existing values. (see below)
- A form value: choose one of the form inputs.
- To the logged-in user: this option is only available when the form is behind a login restricted to a specific user role.
- To the current date (for date fields only)
- To the user's current location (for address fields only when the user is logged in and they have location services enabled on their browser)
Append/Remove Multiple Values
When using multiple choice fields or "many" connection fields with record rules, you can use the custom value option to either, replace, append or remove values from the field.
To use this option, select the "to a custom value" option in the "Values" section while building your record rule. This will give you three options:
- By replacing with: this option will replace the current field value with whatever values are selected in the rule when the rule triggered.
- By adding: this option will append the value(s) selected in the rule to any existing values in the field when the rule is triggered.
- By removing: this option will remove the value selected in the rule if it exists in the field when the rule is triggered.
Order of Execution
Record rules have a specific order of execution in which they run when a form is submitted. In general all rules (update a record, insert a connected record and update a connected record) run simultaneously on a form, they do not run top-to-bottom.
However there are some exceptions:
- Update this record rules calculate before any Record formulas or equations in fields. So, if a record rule is dependent on a formula or an equation, the record rule will calculate based on the old value of that field.
- Record rules that "Insert connected record" or "Update connected record" are calculated after any formulas or equations in fields. So, if a record rule is dependent on a formula or an equation, the record rule will calculate based on the new value of that field.
- Emails are not sent until all appropriate record rules have fired, so if your emails are not going out but look as though they ought to be, make sure that record rules are not preventing their field-specific conditions from being met.
- For example, an email will not be sent if it needs a yes/no field's value to be no, but a record rule is changing that value to yes.
Notes & Troubleshooting
- Remember that if you want to set a connection field via a record rule, you can only set its value to a record’s connection field’s value; trying to set it with a name or auto increment (ID) field, for example, will not work.
- If you're trying to assign the logged-in 'user role' but don't see it as an option, make sure the login restriction is allowing the specific user role to access this page.
- Equation fields' values can be used to set the values of other fields when inserting a connected record, but record rules which update the form's record can not currently use that record's equation fields' values to set the values of other fields on the same record.