# Creating and attaching script validators

## Creating a validator <a href="#walidatoryskryptowe-validationscript-tworzeniewalidatora" id="walidatoryskryptowe-validationscript-tworzeniewalidatora"></a>

A script validator is one of the artifact types in the repository. To add a script validator, go to the tab **Library → Script validators**, and then click the button on the right-hand side **Add script validator.**

<figure><img src="/files/8b930599c185485873c1ade40b8fa792de6ba487" alt=""><figcaption><p><em><strong>Figure 1.</strong> Adding script validators</em></p></figcaption></figure>

## Edit window <a href="#walidatoryskryptowe-validationscript-oknoedycji" id="walidatoryskryptowe-validationscript-oknoedycji"></a>

The edit window in the repository allows you to change the validator content as well as the returned keys and default error messages. In the **Parameters** section, all items resulting from the validator input code and output (error keys) should be added. The parameters window can be displayed by clicking the button in the left panel ![](/files/fac37fd6bc80e8d9ddc6c7596b434ba692b17d86).

More information about the editor itself can be found in the [Script validator editor](/documentation/documentation-en/budowanie-aplikacji/logika-biznesowa/scriptcode/walidatory-skryptowe-validationscript/edytor-walidatorow-skryptowych.md).

<figure><img src="/files/bc417124413bdbd28a88f1f8840bf8a504d9435e" alt=""><figcaption><p><em><strong>Figure 2.</strong> Script validator edit window</em></p></figcaption></figure>

## Attaching to an application <a href="#walidatoryskryptowe-validationscript-podpiecienawniosku" id="walidatoryskryptowe-validationscript-podpiecienawniosku"></a>

Attaching a script validator to an application does not differ from attaching a standard validator. For a specific component in the **Properties** panel, select **Data quality → Validators → Add validator**, and then search for its name. In the **Input parameters** tab, select the appropriate component in the field **Select a component or constant**.\
The switch in the column ***Call when empty*** 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).

<figure><img src="/files/ac3f904ed39c39d6a436024ffa42b079c7e3d534" alt=""><figcaption><p><em><strong>Figure 3.</strong> Attaching a script validator to an application</em></p></figcaption></figure>

## Creating a validator error message <a href="#walidatoryskryptowe-validationscript-tworzeniekomunikatubleduwalidatora" id="walidatoryskryptowe-validationscript-tworzeniekomunikatubleduwalidatora"></a>

The content of the error message (key translation) of a script validator 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 content of the script validator:

<figure><img src="/files/611e3f8322865f5e7fa9f90308f2dfc6ed435fcf" alt=""><figcaption><p><em><strong>Figure 4.</strong> Translation of the script validator key</em></p></figcaption></figure>

\
Edit the translation column and enter the text of the message that should appear if the validator returns a specific 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 error message in the component/application as follows: {0} for the first parameter, {1} for the second parameter, {2} for the third, etc.

```
let minimalAge = 18;
let maximalAge = 25;
if (minimalAge > ageDifference || maximalAge < ageDifference) {
            return [{
            'key': 'pl.LCL_birthDate.outOfRange',
            'parameters': [minimalAge, maximalAge, 'This application can be submitted by people aged {0}-{1}.']               
        }];

```

<figure><img src="/files/8dcf8c3c320f2a346f2804a2b2c671fd68998d5d" alt=""><figcaption><p><em><strong>Figure 5.</strong> Translation of the script validator key populated with variables</em></p></figcaption></figure>

<figure><img src="/files/31a36e183321e7cebaf1154a0b59eac5e6fbf2fd" alt=""><figcaption><p><em><strong>Figure 6.</strong> Error message content visible in the application</em></p></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.eximee.com/documentation/documentation-en/budowanie-aplikacji/logika-biznesowa/scriptcode/walidatory-skryptowe-validationscript/tworzenie-i-podpiecie-walidatorow-skryptowych.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
