> 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/api-walidatorow-skryptowych.md).

# Script Validators API

## Sample validator code <a href="#walidatoryskryptowe-validationscript-przykladowykodwalidatora" id="walidatoryskryptowe-validationscript-przykladowykodwalidatora"></a>

Below is an example code that shows how to use input and how data should be returned:

```javascript
function callService(context) {
    let input1 = context.getFirstParameter("input1");
    if (input1 === "api") {
        return [{
                'key': 'pl.error',
                'parameters': [input1, "parameter {0} is incorrect"]
            }
            ];
    } else if (input1 != null && input1 !== "") {
        return [{
                'key': 'pl.error',
                'parameters': [input1, "another hardcoded parameter"]
            }];
    } else {
        return [];
    }
}
```

## Entry to the script validator <a href="#walidatoryskryptowe-validationscript-wejsciedowalidatoraskryptowego" id="walidatoryskryptowe-validationscript-wejsciedowalidatoraskryptowego"></a>

As input (parameter *context* in the code above) there is an object that provides the following methods:

* List\<String> **getParameters**(final String name) - retrieves a specific list from the input data map,
* String **getFirstParameter**(final String name) - retrieves the first element from a specific list from the input data map or returns the value "null",
* String **getFirstParameter**(final String name, final String defaultIfEmpty) - retrieves the first element from a specific list from the input data map, and if it does not exist or is empty returns the value "defaultIfEmpty",
* Map\<String, List\<String>> **getInputParameters**() - returns the entire input data map it stores,
* String **isVisible**(final String id) - retrieves information whether a component with the given id is visible,
* String **getValue**(final String id) - retrieves the value of the component (also session variable) with the given id,
* String **getData**(final String id, final String attribute) - retrieves the value of a specific attribute for a component with the given id (**NOTE!** Available attributes depend on the component),
* List\<Map\<String, String>> **callService**(String name, Map\<String, List\<String>> input) - allows calling ServiceProxy,
* ValidatorOutput **validate**(String name, Map\<String, List\<String>> input) - allows calling the validator,

Example of retrieving a list (e.g. for fields in a repeatable section):

```javascript
function callService(context) {
    let inputFromRepeatableSection = context.getParameters("inputFromRepeatableSection").toArray();
}
```

## Output from the validator <a href="#walidatoryskryptowe-validationscript-wyjsciezwalidatora" id="walidatoryskryptowe-validationscript-wyjsciezwalidatora"></a>

1. **Map list:** array of objects containing the fields "key" and "parameters".
2. Optional fields:
   1. type - validator type is set to INLINE by default, another option is POPUP,
   2. parameters - variables that we can send to the script validation message
   3. attributes -\
      e.g. POPUP attributes adding a 'next' button and changing e.g. the component value after pressing 'next':

```javascript
return [{
          'key': 'pl.errorPopup',
          'parameters': [input, 'The provided value is incorrect'],
          'type': 'POPUP',
          'attributes': {
              'componentUpdateId': componentID,
              'componentUpdateValue':'potato'
          }
      }];
```

e.g. attributes for GesTable row validation:

Example INLINE validation - GesTable rows

```javascript
return [{
          'key': 'pl.errorGesTable',
          'parameters': [input, 'The provided value is incorrect'],
          'type': 'INLINE',
          'attributes': {
              'colName': 'columnName',
              'rowId':id
          }
      }];
```

## Logging <a href="#walidatoryskryptowe-validationscript-logowanielogowanie" id="walidatoryskryptowe-validationscript-logowanielogowanie"></a>

Logging input data is automatic.

Manual logging should be consistent with the description in [Logging in ScriptCode](https://docs.eximee.com/documentation/documentation-en/budowanie-aplikacji/logika-biznesowa/scriptcode/logowanie-w-scriptcode.md)

## Throwing business exceptions <a href="#walidatoryskryptowe-validationscript-rzucaniewyjatkowbiznesowych" id="walidatoryskryptowe-validationscript-rzucaniewyjatkowbiznesowych"></a>

Business errors have been described in detail on the page [Error pages](https://docs.eximee.com/documentation/documentation-en/budowanie-aplikacji/interfejs-uzytkownika/formularze/tworzenie-formularza/strony-bledow.md#bledy-biznesowe).

{% hint style="info" %}
**Validator examples:**

demoEmailWalidator, demoPESELWalidator, demoDowodWalidator, demoMinMaxWalidator
{% endhint %}


---

# 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/api-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.
