githubEdit

Compliance Text Search

circle-info

Available from version 11.48.0 — Requires OPENSEARCH_ENABLED license.

What does this script do?

Searches for compliance-relevant text like "REVERSE CHARGE" in the document archive. If matching documents exist, the tax code is automatically set. Supports both exact phrase matching and fuzzy search (typo-tolerant for OCR errors).

Trigger

AFTER_FORMATTING on document type INVOICE

Full Script

# Search for "REVERSE CHARGE" in the organization's document archive
rc_docs = fulltext_search(
    "REVERSE CHARGE",
    search_type="match_phrase",
    doc_type="INVOICE",
    size=5
)

if rc_docs:
    set_field_value(document_data, "tax_code", "RC")

Variant: Fuzzy Search (OCR Error Tolerant)

Step-by-Step Explanation

  1. Search the archive for the exact phrase "REVERSE CHARGE" using fulltext_search()

  2. Filter by document type to only search invoices

  3. If found: Automatically set the tax code field to "RC"

  4. Fuzzy variant: Use search_type="fuzzy" to catch OCR misreads (up to 2 character differences)

Functions Used

Last updated

Was this helpful?