Using Record Rules

In this article, we will explore how you can make the most of Knack's record rules in form views and grid views.

This article covers the following topics:

 

What are record rules?

Record rules are a specialized type of rule that empowers users to automate precise actions in the background when they submit a form or edit a grid inline in the Live App.

These rules have the capability to:

  • Update the record the view is using 

  • Update connected records

  • Insert new connected records

 Below are some typical use cases for 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.

Tip: Record rules are a part of form views, so it will be helpful to be familiar with how to use this type of view. You can find a refresher on using form views here.

Note: Actions such as update this record, update connected records, insert a connected record, and send a custom email can also be triggered using Action Links. See details in the Using Action Links article.

 

Managing Record Rules

Record rules are available on form views and grid views while inline editing. In order to add, edit, or delete record rules, you must first take one of the following actions: add a new form or grid, edit an existing form view, or enable inline editing on a grid.

Tip: You can learn more about form views and grid views here.

Adding 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 grid view to open the view editor.

Adding a Record Rule to a Form

After opening the view editor, navigate to the left toolbar and select "Rules". Then, choose the "Record Rules" section.

recordrules1

recordrules2

After navigating to the "Record Rules" tab in the view editor, simply click on "Add Rule" to successfully add your first record rule.

recordrules3

Once you have added a record rule, you have the ability to define its functionality. This involves specifying the action that will be triggered, determining when it will run, and identifying the values that the rule will update.

Tip: For more information on record rule settings, please refer to the section below.

 

Adding a Record Rule to a Grid

Inline editing will need to be enabled before record rules can be added to a grid view. You can enable inline editing from the settings section of the view editor.

recordrules4

After enabling inline editing, you can conveniently add record rules to specific grid columns by modifying the column properties.

recordrules5

Note: Please note that at this time, record rules configured in Grid views to send a custom email will not have an email delivery history available. To learn more about email delivery history see our article here

 

Editing a Record Rule

To edit an existing record rule, simply locate the form that the rule is on in your Builder and open the view editor. From there, select "Rules" and then select "Record Rules".

There any record rule settings can be edited for existing rules.

recordrules5

 

Deleting a Record Rule

To remove existing record rules when editing a form view, simply click on the trashcan icon located in the top right corner of the rule.

recordrules7

 

Copying a Record Rule

To make a copy of existing record rules while editing a form view, simply click on the copy icon located in the top right corner of the rule.

recordrules8

Moving a Record Rule

When editing the record rules, you have the ability to rearrange them, which can be quite useful in managing multiple record rules efficiently. Simply click the icon highlighted below, and you can drag and drop the record rule to the position/order you would like it to be in. 

recordrules9-1

Note: Moving record rules does not change the order of execution.

 

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

recordrules10

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  that you can track who submitted a comment, rating, or ranking forms.

Examples:

  • Assign the logged-in user to the table'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 value.

Note: If your record rule is configured to retrieve data from a connected record, but the rule appears to be ineffective, it is important to verify whether the record you are working on is indeed connected.

You can do this by examining the connection field of the record. If the field is empty, that indicates that the record is not connected. 

 

See the following articles 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 table to insert a record into.

Note: Your form’s table must be connected to at least one other table for this option to be available.

recordrules11

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 table to insert a record into.

Note: Your form’s table must be connected to at least one other table for this option to be available.

recordrules12

This feature is particularly useful for seamlessly adding new notes to a project or creating a comprehensive version history of records that can be easily accessed within the Live App.

For example, upon submitting a form which edits a record, insert a new connected record of the same table 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.

Tip: You can learn 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.

recordrules13

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. 

You can trigger record rules "When" with different filters:

Filter

Description

contains

triggers when the field contains the set value

does not contain

triggers when the field does not contain the set value

is

triggers when the field is a specific value

is not

triggers when the field is not a specific value

starts with

triggers when the field starts with a specific value

ends with

triggers when the field ends with a specific value

is blank

triggers when the field is blank

is not blank

triggers when the field is not blank and contains any value.

has changed

triggers when the field has been changed from its previous value

has changed to

triggers when the field has been changed from its previous value to a new specific value

has changed from

triggers when the field has been changed from a specific previous value to a new value

Note: It is important to note that if you add multiple conditions, all conditions must be met in order for the action to be performed.

 

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 are 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.

recordrules14

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, and 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 more information 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) This option will set the Date/Time field to the current date.

  • To the user's current location: This option is for Address fields only, when the user is logged in, and when they have location services enabled on their browser.

 

Append/Remove Multiple Values

When using multiple choice fields or "many-to-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 the values that 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.

recordrules15

Order of Execution

Record rules follow a specific order of execution when a form is submitted. It's important to note that all rules, including updating a record, inserting a connected record, and updating a connected record, run simultaneously on a form.

They do not execute in a top-to-bottom manner.

However, there are some exceptions:

  • Update this record rules are calculated prior to any record formulas or equations in fields. Therefore, if a record rule depends on a formula or an equation, the record rule will be calculated based on the previous value of that field.

  • Record rules for "Insert connected record" or "Update connected record" are processed after any formulas or equations in fields. This means that if a record rule depends on a formula or an equation, the record rule will be calculated based on the updated value of that field.

  • Emails will not be sent until all relevant record rules have been triggered. If you are experiencing issues with emails not being sent despite appearing to meet the necessary conditions, please ensure that record rules are not blocking the fulfillment of their field-specific requirements.

    • 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

  • Please keep in mind that when setting a connection field using a record rule, you can only assign its value to another field connected to the record. Attempting to set it with a name or auto-increment (ID) field will not be successful.

  • If you are attempting to assign the logged-in user role but cannot find it as an option, please ensure that the login restriction allows the specific user role to access the 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.

  • Currently, record rules that are set up to send custom emails do not have access to an email delivery history.