> For the complete documentation index, see [llms.txt](https://docs-it.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-it.docbits.com/administration-and-setup/settings/global-settings/document-types/script/scripting-in-docbits.md).

# Scripting in DocBits

## Guida allo Scripting di Docbits

Benvenuti nella guida allo scripting di Docbits! Qui imparerete come utilizzare gli script per automatizzare e migliorare l'elaborazione dei documenti in Docbits. Gli script consentono la manipolazione personalizzata dei campi, la trasformazione dei dati e l'implementazione di logiche su vari tipi di documento.

### Per Iniziare

Gli script in Docbits sono scritti in Python. Interagiscono con i campi e i metadati dei documenti per eseguire un'ampia gamma di operazioni, dalla semplice formattazione dei dati alla logica complessa.

#### Funzioni Chiave

* `get_field_value(fields_dict, field_name, default=None)`: Recupera il valore di un campo specificato.
* `set_field_value(fields_dict, field_name, value)`: Imposta il valore di un campo specificato.
* `create_new_field(field_name, value)`: Crea un nuovo campo con un nome e un valore specificati.
* `format_decimal_to_locale(value, locale)`: Formatta un valore decimale secondo una localizzazione specificata.

### Script di Esempio

Di seguito sono riportati diversi esempi che dimostrano attivita di scripting comuni.

#### Esempio 1: Mappatura Valute per Fatture

Standardizzare i simboli o il testo delle valute nei codici valuta ISO.

```python
currency_map = {
    "€": "EUR",
    "EURO": "EUR",
    "$": "USD",
    "£": "GBP"
}
currency_value = get_field_value(fields_dict, "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(fields_dict, "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 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-it.docbits.com/administration-and-setup/settings/global-settings/document-types/script/scripting-in-docbits.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.
