> For the complete documentation index, see [llms.txt](https://docs.docbits.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.docbits.com/polish/administration-and-setup/settings/global-settings/document-types/script/scripting-in-docbits.md).

# Skrypty w DocBits

## Film instruktażowy: najważniejsze funkcje skryptów

{% embed url="<https://docbits-videos.fra1.cdn.digitaloceanspaces.com/settings-assistant/doc-config-script-functions/v3/pl.mp4>" %}
Najważniejsze funkcje skryptów w DocBits
{% endembed %}

Film pokazuje w edytorze skryptów, jak odczytać pole (`get_field_value`), ustawić wartość (`set_field_value`), obliczyć termin płatności (`set_date_value`), oznaczyć pole jako nieprawidłowe (`set_field_as_invalid`) i uczynić je obowiązkowym (`set_is_required`).

## Przewodnik po skryptach Docbits

Witamy w przewodniku po skryptach Docbits! Tutaj dowiesz się, jak używać skryptów do automatyzacji i ulepszania przetwarzania dokumentów w Docbits. Skrypty umożliwiają niestandardową manipulację polami, transformację danych i implementację logiki w różnych typach dokumentów.

### Pierwsze kroki

Skrypty w Docbits są pisane w języku Python. Wchodzą w interakcję z polami dokumentów i metadanymi, aby wykonywać szeroki zakres operacji, od prostego formatowania danych po złożoną logikę.

#### Kluczowe funkcje

Każdy skrypt otrzymuje dokument pod nazwą `document_data`. Przekazuj go jako pierwszy argument do funkcji pól. Pełną dokumentację znajdziesz na stronie [Funkcje Pol](/polish/administration-and-setup/settings/global-settings/document-types/script/scripting-in-docbits/field-functions.md).

* `get_field_value(document_data, field_name, default_value=None, is_clean=False)`: Odczytuje wartość pola.
* `set_field_value(document_data, field_name, value)`: Zapisuje wartość w polu i tworzy pole, jeśli nie istnieje.
* `set_date_value(document_data, field_name, value, add_days=0, skip_weekend=False)`: Zapisuje datę, opcjonalnie z dodaniem dni i pominięciem weekendów.
* `set_amount_value(document_data, field_name, value)`: Zapisuje kwotę sformatowaną zgodnie z lokalizacją dokumentu.
* `set_field_as_invalid(document_data, field_name, message, code=None)`: Oznacza pole jako nieprawidłowe i wyświetla użytkownikowi komunikat.
* `set_is_required(document_data, field_name, value)`: Ustawia pole jako wymagane lub opcjonalne.

### Przykładowe skrypty

Poniżej znajduje się kilka przykładów demonstrujących typowe zadania skryptowe.

#### Przykład 1: Mapowanie walut dla faktur

Standaryzacja symboli walut lub tekstu do kodów walut ISO.

```python
currency_map = {
    "€": "EUR",
    "EURO": "EUR",
    "$": "USD",
    "£": "GBP"
}
currency_value = get_field_value(document_data, "currency", None)
if currency_value:
    currency_value = currency_value.upper()
    if currency_value in currency_map:
        currency_value = currency_map[currency_value]
    set_field_value(document_data, "currency", currency_value)
```


---

# 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.docbits.com/polish/administration-and-setup/settings/global-settings/document-types/script/scripting-in-docbits.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.
