Using Object Validation Rules

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 

When do Validation Rules trigger?

Validation Rules can be triggered when manually (or through the API) editing or creating a record, or when making edits to a Lead Status, Opportunity or Quote Status, Opportunity or Project Pipeline Stage, or when converting a Lead. They will not trigger when Insightly Workflow Automations are creating or editing those records, or when a record is being created through conversion.

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 should be equal to the first name Steve.
  • In addition to if-else statements, the contains () method can also be utilized. The formula below is an example of the contains () method where first name field contains the first name Steve.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 specific users from editing records or specific fields beyond what is possible using Field Level Permissions or Advanced Permissions. 

How to Create a Validation Rule

  1. Click the profile icon and click System Settings.

  2. Click Objects and Fields.

  3. Select the object you want to create the rule for. 

  4. Click Validation Rules and click New Rule. 

  5. 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 be equal to Steve.

    • Error Message - Type the message you want to display when your rule is met.

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

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

      Here is an example of a formula for Contacts. This formula checks whether an email is present and whether that email is valid by checking if it has the @ symbol.
  8. 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.

  9. Click Create Validation Rule.

To save the validation rule, you must return a value and validate the formula.




Was this article helpful?