Check that a field is present
For example, check that theMyField field is found and filled in:
Compare floating-point numbers
Comparing floating-point numbers directly can yield unpredictable results. Use methods from the built-inMath object to compare numbers — especially money values — reliably.
Require a non-empty value depending on another field
An optional field can become required based on another field’s value. For example, ifMaritalStatus is Married, the spouse name fields should be filled in.
This script rule verifies that when MaritalStatus is Married, both SpouseFirstName and SpouseLastName are filled in:
Check that a field is located on the document
Rules can also fill in field values, even if the value isn’t printed on the document. For example, if several taxes apply, the total tax can be calculated automatically. However, some countries require the total tax amount to be printed on the document. This script rule checks that for receipts from Germany the total tax is present on the image. For other countries, no additional check is needed because the Required field flag is turned on for the total tax field:Validate the data in particular cases
Checking that the total tax equals the sum of all taxes can be done with a predefined rule (Check Sum). But if one of the taxes can have a negative value in certain countries, only a script rule can handle both cases — adding all taxes, or adding and subtracting a return tax, depending on the country of origin. This script checks that the sum of two taxes equals the total tax, except for receipts from Spain, where either the sum or the difference of the two can equal the total tax:Compare a column sum to an external field
Scripts can reference table values, not just regular fields. To speed up rule checks, save tables as variables and reference the variables instead of re-fetching the table. If a variable holds an entire table, use theInstances property to access rows, then use GetChild to get a specific cell in a row.
The sample below sums all values in the Total Price column and compares the result to the Total field:
Compare column cells to an external field and list failing rows
Reference table columns withContext.GetFields to get every cell in the column, which is useful for looping.
The sample below compares each row’s tax rate to the overall tax rate. When values don’t match, the script continues instead of failing immediately, collecting the row numbers with mismatches and reporting them in the error message:
Compare the product of row values to another row value
You can perform operations on different columns in a table row-by-row without using explicit loops — reference each column usingContext.GetField. This creates a repeating rule that runs automatically for each row. All columns referenced this way must belong to the same table.
The sample below multiplies unit quantity by unit price for each row and compares the result to the line item’s total price:
Related topics
Business rules automation
Add scripted rules to a Document skill, configure readable and writable fields, and reference table columns.
Object model
Full JavaScript object reference for use in Advanced Script Rules.
Context
The Context global object — access the document, fields, and skill parameters from inside a rule.
Field
The Field object — inspect and modify a document field during rule execution.
