> 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="https://2112972046-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2CssJT0zIo4SJQLbSZ6l%2Fuploads%2FojbL83aL5vYYiRnu0yCl%2Fimage.png?alt=media&amp;token=841f51d4-0e7c-42f7-9fbb-cd4522496078" 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 ![](https://2112972046-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2CssJT0zIo4SJQLbSZ6l%2Fuploads%2FlcsQX63BJLjsjRv1no0n%2Fimage.png?alt=media\&token=3d1b4f04-bad2-4656-b0d6-1520fc814dcf).

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

<figure><img src="https://2112972046-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2CssJT0zIo4SJQLbSZ6l%2Fuploads%2F1dtppZw8rgiRMfjB0YX1%2Fobraz.png?alt=media&amp;token=d2c96196-58ba-44f1-aac9-9553a892c89e" 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="https://2112972046-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2CssJT0zIo4SJQLbSZ6l%2Fuploads%2Fc8AxoQJA5ifkjQjEfbll%2Fimage.png?alt=media&amp;token=db68e283-e499-4cd4-8fba-e242c6644d65" 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="https://2112972046-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2CssJT0zIo4SJQLbSZ6l%2Fuploads%2FwWKQM0nWS9hQtTcy3tHg%2Fimage.png?alt=media&amp;token=a35b71eb-59fe-4471-8ab5-bf1196dc207c" 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="https://2112972046-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2CssJT0zIo4SJQLbSZ6l%2Fuploads%2FEodT5VCbrwNK3W4ORHoN%2Fimage.png?alt=media&amp;token=b539cff0-4330-41cf-9b8c-3b55c1f6a118" alt=""><figcaption><p><em><strong>Figure 5.</strong> Translation of the script validator key populated with variables</em></p></figcaption></figure>

<figure><img src="https://2112972046-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2CssJT0zIo4SJQLbSZ6l%2Fuploads%2FCXXOfiYPEMMv0VGs0ceS%2Fimage.png?alt=media&amp;token=394a11cf-a017-4418-822c-4e57c1fc6484" 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
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=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
