This article aims to provide comprehensive information on how to utilize page rules within the Pages section of the Knack Builder.
What are page rules?
Page rules are actions that can be automatically triggered based on conditions you define as soon as a user opens a page.
For example, consider a scenario where users can register for an event with limited availability. In such cases, you can employ a page rule to automatically hide the registration form when the availability reaches zero.
Here are a few additional instances that demonstrate how you can make use of page rules:
- Hide a form to edit a record if the user role of the logged-in user is not an “Editor”.
- Hide a form to register for a class if the class attendance has exceeded a specific size.
- Redirect to a registration form if the logged-in user hasn’t registered.
- Warn the user if they need to update their data or complete some information.
Note: Page rules can be applied to child pages or start pages with user logins enabled. However, it is important to note that page rules cannot be triggered based on values in multi-record views such as grids, lists, maps, calendars, and so on.
Managing Page Rules
Adding a Page Rule
You can access Page Rules in the Builder by selecting the down arrow menu option next to the page’s name or by selecting "Rules" on the top menu. When you select this option, the page rule settings will be displayed in the toolbox on the left side of the screen.
There, you can add a new rule by selecting "Add Rule".
Editing a Page Rule
Existing page rules can be accessed and edited at any time from the same down arrow menu option next to the page’s name or by selecting "Rules" on the top menu. To modify a page rule, you have the flexibility to add or remove any criteria using the "+" or "-" icons.
You can drag/drop each individual rule using the left anchor bar to keep your rules organized. You must press the "Save Changes" button in order for your changes to take effect.
Deleting a Page Rule
To get rid of a page rule entirely, use the trashcan delete icon to the right of the rule panel. You must press the "Save Changes" button in order to save your changes permanently.
Building Page Rules
Defining the Conditions
Page rules are triggered when certain conditions that you specify are met during the loading of a page. These conditions are added in the section titled "When the following criteria is true".
To define your conditions, you select a specific field and then specify the criteria for that field. For example, if you want to display a message when a status field is set to overdue, the criteria would need to check if the status field is indeed set to overdue in order for the rule to be triggered.
The fields available to use will depend on the page. Child pages will let you choose fields from the table that page is based on, or a connected table's fields. If the page is protected by a login, you will also be able to use fields from the account table and other user roles associated with that page's login.
In other words, fields from the source table of the page as well as fields from the user roles that have access to the page will be available to use in your page rules. If no fields are available, the "Rules" link will not be available.
You will need to check for at least one condition, but you can add as many as you need in a single rule. If you have multiple fields selected, they must all be true in order for the rule to trigger.
Defining the Action
Each rule can perform only one action. To add an action, go to the section titled "Run the following action" and select the action that you want your page rule to perform.
There are four main actions a page rule can perform:
Show a message
Redirect to an existing page in your app
Redirect to another website URL
This action type will hide any selected views when your criteria match.
The "Show a message option" will display a message of your choice. The message will be displayed at the top of the page, above any views.
There are four different messaging styles available; they each have a unique background color for different effects: "Neutral", "Confirmation", "Warning", and "Red Alert".
You can choose whether the message can be dismissed by the user or not. If toggled, an "X" icon on the top-right corner of the message will be displayed.
Redirect to the Parent Page
Once this action is set, the user will be redirected back to the page that the child page originates from (otherwise referred to as the parent page).
Note: This action is only available for child pages.
To learn more about page types, see our article here.
Redirect to an Existing Page
This action will redirect the user to a specific page within the app of your choosing. All starting pages are available as well as any other child page that has the same table as a source. If the child page is meant to display a specific record, the same record as the current page will be used.
Redirect to Another Website URL
With this action, you can add an external website URL to redirect your users to.
Note: There are no "back" crumbtrail links generated when this option is selected, so if you’re linking to an external website, the only way back to you Knack page is by using the browser's back and forward arrow buttons.
How Multiple Rules Work
It is important to understand that when you have multiple rules, all matching rules will be triggered simultaneously. This applies even to rules that have the same criteria.
Knack does not stop triggering rules after the first match.
Take the following scenario for example:
In the above image, there are two page rules that will trigger when the customer’s user status is "active". The first rule will hide a view and the second rule will display a message.
In this scenario, both rules will trigger, so the user will see a message and the view will be hidden as well.
If we tweak the above scenario, the second rule will now redirect the user instead:
Technically, both rules are still going to trigger, but since the user is being redirected out of the page, they are never going to see the first message.
In this knowledge article, you will find a detailed step-by-step guide on how to create a registration form with limited availability. Additionally, it will explain how to utilize page rules to automatically hide the form and display a message when the availability reaches zero.
Notes & Troubleshooting
If you have multiple fields selected, they must all be true in order for the rule to trigger.
Page rules run before views on the page are rendered in the Live App. This allows for re-directs to be put in motion or only "show" views to be displayed.