githubEdit

Table Functions

Functions for reading, writing, and manipulating tables and table rows.

Source: module/script/helper/document_table_script_functions.py


get_column_value()

Reads the value of a column from a table row.

get_column_value(row, column_name, default_value=None, is_clean=False)

Parameters:

Name
Type
Description

row

dict

A row object from table["rows"]

column_name

str

Column name (case-insensitive)

default_value

any

Return value if column is empty/missing

is_clean

bool

If True: UPPERCASE with spaces removed

Example — Iterate table rows:

table = tables_dict.get("INVOICE_TABLE")
if table:
    for row in table["rows"]:
        desc = get_column_value(row, "DESCRIPTION", "")
        qty = get_column_value(row, "QUANTITY", "0")
        price = get_column_value(row, "UNIT_PRICE", "0")
circle-info

Column name comparison is case-insensitive: "DESCRIPTION" also matches "description" or "Description".


set_column_value()

Sets the value of a column in a table row.

Returns: True if value changed, False if identical

Side effects:

  • Sets extraction_method = "SCRIPT"

  • Automatically creates the column if it does not exist

Example — Calculate line totals:


set_column_date_value()

Sets a date value in a table cell with formatting and date arithmetic.

Parameters:

Name
Type
Description

document_data

dict

Required for date_format_pattern

row

dict

Table row

column_name

str

Column name

value

str

ISO date "2026-03-25"

add_days

int

Days to add

skip_weekend

bool

Skip weekends

exclude_final_days

str/list

Days to exclude

Example — Calculate delivery dates per row:


set_column_amount_value()

Sets an amount value in a table cell with locale formatting.

Example — Calculate and format line totals:

circle-info

value is automatically converted to str() before being set.


add_table_column()

Adds a new column to all rows of a table.

Parameters:

Name
Type
Description

table

dict

The table object (not tables_dict!)

col_name

str

Name of the new column

default_value

any

Initial value for all rows

Side effects:

  • is_extra_column = True (marked as non-original)

  • is_mapped = True

  • extraction_method = "SCRIPT"

Example — Add tax code column:

circle-exclamation

remove_rows_from_table()

Removes a specific number of rows from a table.

Parameters:

Name
Type
Description

table_name

str

Name of the table

count

int

Number of rows to remove

start

int

Start index (0-based)

Raises: ValueError if start or count is out of range

Example — Remove header rows or last row:


remove_all_rows_except_one_from_table()

Keeps only one specific row and removes all others.

Parameters:

Name
Type
Description

line_number

int

Row number (1-based!)

circle-exclamation

Example:


delete_tables()

Deletes all tables from the document (with backup).

Side effects:

  • Saves tables under last_deleted_table

  • Removes po_items, po_multi_matched, po_match_status

Example:


restore_tables()

Restores tables previously deleted with delete_tables().

Example:

circle-check

Common Patterns

Calculate column sum

Filter empty rows

Compute column from other columns

Last updated

Was this helpful?