Adding Custom Validations

Available Liferay 7.4 U27+ and GA27+

With custom Objects, you can add validations for both custom and metadata fields. Validations set rules used for determining valid field entries and are defined using either Groovy scripts or Liferay’s expression builder. Each validation has its own trigger, conditions, and error text, which you can set via the Objects UI. When triggered, the validation checks for valid field entries according to your defined conditions and displays your error text for invalid entries.

Create validations for custom and metadata Object fields.


The desired data fields must exist before you can create validations for them.

Follow these steps to add a custom validation:

  1. Open the Global Menu (Global Menu), click the Control Panel tab, and go to Objects.

  2. Begin editing a custom Object.

  3. Go to the Validations tab and click the Add button (Add Button).

  4. Enter a label and select a validation type: Groovy or Expression Builder.

    Enter a label and select a validation type.

  5. Click Save.

  6. Begin editing the newly created validation.

  7. Go to the Conditions tab and add conditions to the validation.

    Add conditions to the validation.

    When using Groovy, you can browse and add available data fields to your conditions via the side panel. See Using Groovy Validations for more information.

    When using Expression Builder, you can browse and add fields, operators, and functions to your conditions via the side panel. See Using Expression Builder Validations for more information.


    Conditions can include multiple fields and functions for complex validations.

  8. Enter a localizable error message. This message is displayed whenever the validation is triggered and field entries do not meet one or more of the defined conditions.

  9. Go to the Basic Info tab and activate the validation.

  10. Select a Trigger Event to determine when the validation is run for field entries.


    Each validation can only have one trigger event.

    Activate the validation and set a trigger event.

  11. Click Save.

Once activated, the validation is run for all new Object entries.

Using Groovy Validations

The Groovy validation type supports all standard Groovy Script capabilities. However, when defining Groovy conditions, you must use the invalidFields variable. This variable should return true for invalid field values and false for valid field values. The error message only appears when invalidFields returns true.


The Groovy type does not currently have a check syntax validation.

Use the side panel to add field elements to your Groovy validations.

Using Expression Builder Validations

The Expression Builder type provides predefined fields, operators, and functions that you can access in the Conditions side panel. Clicking an element adds it to the conditions editor. These functions return a Boolean value. For some, true indicates an valid entry, while for others true indicates an invalid entry. See Expression Builder Validations Reference for a complete list of provided operators and functions.


Expression Builder validations can only be used with text, numeric, date, and boolean field types.

Use the side panel to add field, operator, and function elements to your validation.

Available Fields Reference

When constructing conditions, you can use any of the Object’s custom or metadata fields. You can also select from relationship fields on the ‘one’ side of a relationship.

The following chart lists all default metadata fields included in custom Objects:




Portal instance where the entry was created


When the entry was created


External reference code for the entry


Site ID in where the entry was created


Date when the entry was last published


Date when the entry was last modified


MVCC version of the entry


ID of the entry’s Object


ID for the entry


Workflow status for the entry


ID of the assigned user in Workflow


Name of the assigned user in Workflow


Date when the Workflow status was last updated


Email address for the entry’s author


First name of the entry’s author


ID of the entry’s author


Last name of the entry’s author


User name of the entry’s author


Unique universal ID for the entry


Besides custom fields, the following metadata fields are listed in the editing sidebar for easy access:

  • Author (userName)

  • Created Date (createDate)

  • ID (objectEntryId)

  • Modified Date (lastPublishDate)

  • User Email (userEmailAddress)

  • Workflow status (status)