Creating and attaching script validators

Creating a validator

A script validator is one of the types of artifacts in the repository. To add a script validator, go to the Library → Script validators, then click the button located on the right side Add script validator.

Illustration 1. Adding script validators

Edit window

The edit window in the repository allows you to change the validator's content as well as the returned keys and default error messages. In the Parameters section you should add everything that results from the validator input code and output (error keys). The parameters window can be displayed by clicking the .

More information about the editor itself can be found in Script validator editor.

Illustration 2. Script validator edit window

Attaching on the application

Attaching a script validator on the application is no different from attaching a standard validator. For a specific component in the Properties panel you should select Data quality → Validators → Add validator, then search for its name. In the Input parameters tab you should select the appropriate component in the Choose component or constant. The switch located in the Call when empty column is responsible for calling the validator even when there is no value in the specified field (e.g., when a value is removed from a text field).

Illustration 3. Attaching a script validator on the application

Creating the validator error message

The content of the script validator's error message (the key translation) must be defined in the component/application after attaching the validator. Adding the message content in the script is not an error, but it will not be visible in the component/application edit window. After attaching the validator, both the key and its translation will display the key name defined in the script validator's content:

Illustration 4. Script validator key translation

You should edit the translation column and enter the message content that should appear when the validator returns a given error message key.

If it is necessary to use variables in the error message, list those variables in the code as parameters (parameters: [value1, value2, etc.]) and then reference them in the component/application error message as follows: {0} for the first parameter, {1} for the second parameter, {2} for the third, etc.

let minimumAge = 18;
let maximumAge = 25;
if (minimumAge > ageDifference || maximumAge < ageDifference) {
            return [{
            'key': 'pl.LCL_dateOfBirth.outsideRange',
            'parameters': [minimumAge, maximumAge, 'This application can be submitted by persons aged {0}-{1} years.']               
        }];
Illustration 5. Script validator key translation populated with variables

Illustration 6. Error message content visible on the application

Last updated

Was this helpful?