What are Record Rules?
Record rules are a type of form rule, which can be found when using form views in the "Pages" section of the Knack Builder. These rules allow you to perform specific actions behind the scenes when a form is submitted in the live app. These rules can update the record the form is using, update connected records, and 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 the form is submitted
How to add a Record Rule
Before you can start using record rules, you will need to add one to your app. To start, navigate to the "Pages" section of your Knack Builder, and select a form view to open the view editor.
Once the view editor is open, select "Form Rules" from the left side menu, and then select the “Record Rules” tab from the top.
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, when it will run, and which values the rule updates.
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. Here you can choose to update the form record, insert a connected record, or update a connected record.
Update the form record
This option will update the primary record the form is working with and 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 Object) 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.
Knack Tip If your record rule references data from a connected record, but the rule does not seem to be updating the field as you set it, ensure first that the value for the connection field which it references is not blank.
Insert a connected record
Add a new record connected to the form’s record. Your form’s object must be connected to at least one other object for this option to be available. Great for adding history, version, and archived records based on the submission.
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.
Update connected records
This option allows you to update any records connected to the record created/updated by the form.
Update the Order last changed date/time field on a parent Order record to the current date and time whenever a Line item child record is updated.
When: When will a Record Rule run?
The "When" section of the record rule, defines the criteria to trigger the rule. When a form is submitted and all the criteria are met, the rule will run.
By default the rule is set to run for every form submission, however you can add criteria based on one or more specific form values. It is important to note that, if you add multiple conditions, all conditions must be met in order for the action to be performed.
Values: What will a Record Rule update?
The "Values" section of the record rules allow you to choose which fields are updated. 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.
A custom value: enter a value manually.
A form value: choose one of the form inputs.
To the logged-in User (for user connection fields on pages which require a login)
To the current date (for date fields only)
- To the user's current location (for address fields only when the user is logged in)
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
Order of Execution
- All rules which update a record are executed first - simultaneously (not top-to-bottom)
- All rules which insert a record are executed second - also simultaneously
- 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.
- Record rules are calculated before any formulas or equations in fields. So if a record rule is dependent on a formula or an equation, the record rule will calculate on the previous value of that field.