About
When you create custom fields and page layouts, you can mark fields as required. You may want to set other types of rules for your records before they can be saved. With object validation rules, administrators can write formulas to verify that certain conditions are met before records are saved. You can create validation rules for all standard and custom objects.
In this Article
How to Use Object Validation Rules
Before you create your validation rule, determine what object type and fields you want to create the rule for. Like calculated fields, formulas are written using C# (C sharp) and must return a Boolean value (true or false). If you're not familiar with C# or any C programming language, get assistance from someone who is.
You can write your formula using if-else statements, but your statements cannot contain:
for loops
do while loops
method declarations
Opportunity and Quote Status Changes
When a status is changed on an opportunity or quote, Insightly will trigger any applicable validation rules and present errors if the record does not pass validation. Statuses can be changed by clicking the record’s pipeline status or through the Change Opportunity Status or the Change Quote Status modal.
Examples
Two simple examples of object validation rules can be found
below. For more examples of object validation rules, read Object Validation Rule Examples.
The formula below is an example of an if-else statement. According to this if-else statement, the first name field for a contact record cannot be equal to the word test.
if (Record.FIRST_NAME == "Test") { return true; } else { return false; }
In addition to if-else statements, the contains () method can also be utilized. The formula below is an example of the contains () method:
// Get value of field, or "" if the field is null var test = Record.ASSISTANT_NAME ?? String.Empty; if( test.Contains("Test") ) { return Validation.IsError; } else { return Validation.IsValid; }
You can create custom error messages when rules are not met, such as letting users know that "test" is not a valid entry for the first name field.
Data validation rules only apply to the web application of Insightly, not sidebars or add-ons. Validation rules can also be used to prevent other users from editing records they don't own.
How to Create a Validation Rule
Click the profile icon and click System Settings.
Click Objects and Fields.
Select the object you want to create the rule for.
Click Validation Rules and click New Rule.
Complete the required fields:
Rule Name – Enter the name for your rule. For example, we are going to create a new rule for contacts called The first name can't equal test.
Error Message - Type the message you want to display when your rule is met.
Select the Error Location for your message. Based on your selection, that is where the error message will display on the record's page. For example, if you select Top of Page, your message will display at the top of the record.
Enter your formula in the Rule Formula field. To help build the formula, click the Helpers button. You can add values to the formula box by double-clicking or dragging any item from the Objects Fields or Functions list, typing directly in the field, or by copying and pasting a provided formula, such as the examples at the end of this article.
Under Object Fields, the different record fields are sorted by type. For example, if you want to view the string fields (text), select String Fields. The Functions list is also sorted by their function types, such as Boolean (True or False), DateTime, and Decimal.
To learn more about the functions, click any function and read the description.
To ensure your rule is met, the return statements need to include one of the two validations:
Validation.IsError to return your error message.
Validation.IsValid to determine the error is clear.
Click Validate Formula to check your formula can compute. If Insightly cannot validate your formula, an error message will display above the formula field stating why.
Click Create Validation Rule.
To save the validation rule, you must return a value and validate the formula.