Business Rules
This article is currently under review. Some content may be incomplete or inaccurate.
Business rules let you write custom JavaScript logic that validates and normalizes extracted field values. Rules run inside a secure sandbox: you have access to field data and a set of helper functions, but no filesystem, network (unless explicitly allowed), or Node.js APIs.
Rule Levels
Each rule operates at one of three levels:
| Level | Scope | Typical use |
|---|---|---|
| Field | Single field value | Format validation, value normalization |
| Document | All fields in one document | Cross-field checks (e.g. line items sum = total) |
| Transaction | All documents in a transaction | Cross-document checks (e.g. passport matches application) |
Rule Types
| Type | When it runs | Purpose |
|---|---|---|
| Normalization | Automatically during the Extract step (and on field edits in the Transaction Viewer) | Rewrite values to a canonical form (dates, currencies, casing, etc.) |
| Validation | At the dedicated Validate step (and on field edits in the Transaction Viewer) | Check values and emit errors/warnings displayed in the Transaction Viewer |
Presets vs Custom Code
You can create rules in two ways:
- Presets: choose from a library of configurable templates (allowed values, regex, date range, number range, arithmetic check, transaction integrity check, metadata match, etc.) and fill in parameters. The code is generated for you. A handful of presets (arithmetic, transaction integrity, compare fields, validate fields against metadata) use a structured visual builder rather than a flat form.
- Custom code: write JavaScript directly in the Monaco editor with IntelliSense support.
Preset-generated code uses the same public scripting API described below. You can always switch a preset rule to custom code by copying the generated code and editing it directly.
Rule Properties
Each rule has metadata properties that control how it behaves. These are configured in the rule creation/edit dialog and are handled by the engine externally: they are not embedded in the rule's JavaScript code.
| Property | Default | Description |
|---|---|---|
| Enabled | On | When disabled, the rule is skipped entirely (it never executes). |
| Severity | Error | Controls how validation failures are reported. When set to Warning, all set_error() calls in the rule are downgraded to warnings after execution. |
| Confirm fields on success | On | When enabled, all fields engaged in a validation rule are auto-confirmed if the rule passes without errors. |
| Weight | None | Display ordering only: higher-weight results appear first in the validation panel. Does not affect execution order. |
Severity override behavior
The severity property acts as a one-directional, post-execution override:
- Error (default):
set_error()produces errors,set_warning()produces warnings, with no override applied. - Warning: all
set_error()calls are downgraded to warnings.set_warning()calls remain warnings. The override never upgrades warnings to errors.
If your rule intentionally uses both set_error() and set_warning() for different conditions, setting severity to Warning will collapse that distinction: both become warnings. If you need fine-grained control (some conditions as errors, others as warnings), leave severity at Error and call set_error() or set_warning() directly in your code as needed.
Scripting API Reference
All function and variable names in the scripting API use snake_case.
Common Functions (All Levels)
These functions are available in field-level, document-level, and transaction-level rules.
set_error(message)
Set the rule result to error. The message is displayed in the Transaction Viewer.
set_error('Invoice number is missing');
For field-level rules, the bound field name is automatically shown as a clickable tag before the message in the Transaction Viewer, so you don't need to include the field name in the message text. Write just the error description:
// Good - field name tag is added automatically by the UI
set_error('Value is required');
// Avoid - "Invoice Date: " prefix would be redundant
set_error('Invoice Date: Value is required');
set_warning(message)
Set the rule result to warning.
set_warning('Amount seems unusually high');
set_success(message)
Set the rule result to success (optional, since rules that finish without calling set_error or set_warning are considered successful).
set_success('All checks passed');