Simple Solutions: Error Message with Link to Resource
Aug 18, 2022
Custom Data Rules are a great way to create custom error messages that help the user resolve the issue.
But did you know you can also embed a custom link into the error message to give them even more assistance?
Yep, you sure can and I'll show you how!
For this example, imagine I have a Quickbase application to capture sales leads.
In this application, I need the lead's address, but it's not always known when the lead is added.
In order to prevent 'bad data' (like unknown or TBD), I want to provide an easy resource in the error message.
Step 1: Identify the error condition
First, what is the error condition?
For our example, it is a blank address field.
However, it can be almost anything we can determine with a formula, such as:
- The format of an order number not being correct
- A date missing when several other fields have certain values in them
- An amount outside of an expected range based on other criteria
Step 2: Identify the resource to link to
For our example, I want to link to Google to allow the user to search for the company address.
However, I want to take it a step further and pre-populate the search with the company name (from the record) and the word "address".
You may want to link to another Quickbase record, an internal website, a reference document, an external site, etc.
The important part for our Custom Data Rule is that it is accessible via a URL.
Step 3: Write the URL variable
To begin the formula, open the table's Advanced Settings and scroll down to Build custom data rules for this table.
In the formula box, I find it easiest to first define a variable where the URL can be placed along with any additional formula components.
For our example, this is the google URL with the search query set to the company name from the record.
A similar example might be a URL for a shipping site with a search query that includes a tracking number from the record.
To create links to other Quickbase records, check out the Action Button Toolbox.
(Part 1) Custom Data Rule Formula:
var text URL = "https://www.google.com/search?q=" & URLEncode([Company] & " Address");
Video: Learn more about using variables in formulas.
Step 4: Write the "If" statement
Once the URL variable is defined we can write our if statement.
It will have 6 parts:
- The "If" function – the function allows us to set a condition and a response
- The condition – what will trigger the error message
- The message – the text that will display in the error prior to the link
- The URL – the HTML used to construct the link along with the variable reference to the URL
- The target – the target will control where the link will open ('_blank' is a new tab)
- The label – the text that will display as a link
To learn more about writing If statements and conditions, check out Mastering the Text Formula. And for more on using HTML in formulas (such as the <a> anchor tag used here), check out the HTML Formula Crash Course.
(Part 2) Custom Data Rule Formula:
If([Address]="","Address is required " & "<a href='" & $URL & " ' target='_blank'>Search Google</a>")
Step 5: Turn on the custom data rule & test
With the formula complete, be sure to check the box above the formula to Turn custom data rules on? and click Save.
(FULL) Custom Data Rule Formula:
var text URL = "https://www.google.com/search?q=" & URLEncode([Company] & " Address");
If([Address]="","Address is required " & "<a href='" & $URL & " ' target='_blank'>Search Google</a>")
Then, test your new error message by causing the error condition.
Saving the record with a blank address, from the form:
Saving the record with a blank address, from Grid Edit:
Learn More About Custom Data Rules
Video: Quality Control with Custom Data Rules
Post: How To Require a File Type for Attachments
Post: Disable Role From Deleting an Attachment
Quickbase Resource: Custom Data Rules
Feeling like a Junkie? Subscribe Now!