githubEdit

Field Functions

Functions for reading, writing, and controlling document fields.

Source: module/script/helper/document_script_functions.py


get_field_value()

Reads the value of a field from the document.

get_field_value(document_data, field_name, default_value=None, is_clean=False)

Parameters:

Name
Type
Description

document_data

dict

The document_data context object

field_name

str

Name of the field (e.g., "invoice_id")

default_value

any

Return value if field is empty/missing (default: None)

is_clean

bool

If True: value is converted to UPPERCASE with spaces removed

Returns: The field value as string, or default_value

Example — Read invoice number with fallback:

# Read field with default value
inv_id = get_field_value(document_data, "invoice_id", "UNKNOWN")

# With is_clean=True: "INV 001" becomes "INV001"
inv_id = get_field_value(document_data, "invoice_id", "", is_clean=True)

What happens: Returns the field value. When is_clean=True, the value is transformed via value.upper().replace(" ", "").strip() — useful for comparisons.


set_field_value()

Sets the value of a field. Automatically creates the field if it does not exist.

Parameters:

Name
Type
Description

document_data

dict

The document_data context object

field_name

str

Name of the field

value

any

New value

remove_link

bool

If True: removes coords, confidence, rule, etc.

Returns: True if value changed, False if identical

Side effects:

  • Sets highlight_field = True (visual indicator in UI)

  • Sets extraction_method = "SCRIPT"

  • Sets formatted_value = value

Example — Conditional value assignment:

What happens: The field value is updated and marked as script-modified. If the field does not exist, it is automatically created with extraction_method: "SCRIPT" and added to both fields and fields_dict.


set_date_value()

Sets a date value with automatic formatting and optional date arithmetic.

Parameters:

Name
Type
Description

value

str

ISO date: "2026-03-25". If empty: today's date

add_days

int

Days to add (e.g., 30 for payment terms)

skip_weekend

bool

Skip weekends when adding days

exclude_final_days

str/list

Additional days to exclude (e.g., "MONDAY,FRIDAY")

Example — Calculate payment due date (30 days, no weekends):

What happens: The date is calculated by adding days (optionally skipping weekends/specific days) and automatically formatted according to the document's date_format_pattern (e.g., %d.%m.%Y for Germany).

Day codes for exclude_final_days: MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY


set_amount_value()

Sets an amount value with automatic locale formatting.

Parameters:

Name
Type
Description

value

str/number

Amount in English format (e.g., "1234.56")

Example — Set net amount:

What happens: The amount is formatted according to amount_format_locale from document_json (e.g., de_DE, en_US).


create_new_field()

Creates a new field dictionary (without adding it to the document).

Returns: Dict with name, value, formatted_value, extraction_method: "SCRIPT"

Example:

circle-check

delete_field()

Removes a field from the document.

Returns: Tuple (doc_json, fields_dict) after deletion

Example:


set_field_as_invalid()

Marks a field as invalid with an error message.

Parameters:

Name
Type
Description

message

str

Error message (displayed in UI)

code

str

Error code (default: INVALID_VALUE)

Side effects:

  • is_valid = False

  • invalidated_by_script = True

  • highlight_field = True

  • validation_message = message

  • validation_code = code

Example — IBAN validation:

What happens: The field is highlighted red in the validation screen with the error message displayed to the user.


set_field_as_valid()

Removes the invalid status from a field.

Example:

What happens: Removes invalidated_by_script, validation_message, validation_code and sets is_valid = True.


set_field_attribute()

Sets an arbitrary attribute on a field.

Example:

See the full list of Supported Attributes below.


set_is_required()

Makes a field mandatory or removes the requirement.

Example — PO number required for purchase invoices:


set_is_readonly()

Makes a field read-only or editable.

Parameters:

Name
Type
Description

value

bool/None

True = readonly, False = editable, None = remove attribute

Example:


set_is_hidden()

Hides or shows a field in the UI.

Example — Show sub-org fields only when relevant:


set_force_validation()

Forces manual validation for a field.

Parameters:

Name
Type
Description

value

bool

True = force validation, False = remove

reset_validation

bool

If True: resets is_validated back to False

Side effects when value=True:

  • force_validation = True

  • is_valid = False (if not yet validated)

  • validation_code = "FORCED_VALIDATION"

Example — Force validation for high amounts:


Supported Attributes

Core Field Attributes

Attribute
Type
Description

value

any

The raw field value

formatted_value

string

Display-formatted value

content

string

Original extracted content

is_required

bool

Whether field is mandatory

is_valid

bool

Validation status

is_validated

bool

Whether field has been validated by user

is_readonly

bool

Whether field is read-only

is_hidden

bool

Whether field is hidden in UI

force_validation

bool

Force user to validate this field

highlight_field

bool

Highlight field in UI

extraction_method

string

How value was extracted (e.g., "SCRIPT")

Validation Attributes

Attribute
Type
Description

validation_message

string

Error message shown to user

validation_code

string

Error code (e.g., "FORCED_VALIDATION", "INVALID_VALUE")

invalidated_by_script

bool

Marks field as invalidated by script

Extraction/OCR Attributes

Attribute
Type
Description

coords

object

Bounding box coordinates on document

confidence

float

OCR/extraction confidence score

score

float

Match/validation score

score_description

string

Description of the score

page

int

Page number where field was found

rule

string

Extraction rule that was applied

Last updated

Was this helpful?