> For the complete documentation index, see [llms.txt](https://docs.eximee.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.eximee.com/documentation/documentation-en/budowanie-aplikacji/logika-biznesowa/scriptcode/walidatory-skryptowe-validationscript/tworzenie-i-podpiecie-walidatorow-skryptowych.md).

# 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 and the returned keys and default error messages. In the section **Parameters** all inputs and outputs resulting from the validator code content should be added (error keys). 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 [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 on the 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 panel **Properties** you should select **Data quality → Validators → Add validator**, and then search for its name. In the tab **Input parameters** you should select the appropriate component in the field **Choose a component or a constant**.\
The switch located in the column ***Call when empty*** is responsible for invoking 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 script validator's error message (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 content:

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

\
You should edit the translation column and enter the text of the message that should appear when the validator returns a specific error message key.

If it is necessary to use variables in the error message, these variables should be listed in the code as parameters (parameters: \[value1, value2 etc.]), and then referred to 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 minimumAge = 18;
let maximumAge = 25;
if (minimumAge > ageDifference || maximumAge < ageDifference) {
            return [{
            'key': 'pl.LCL_dateOfBirth.outOfRange',
            'parameters': [minimumAge, maximumAge, 'This application can be submitted by people aged {0}-{1} years.']               
        }];

```

<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> The error message content visible on the application</em></p></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` 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>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
