Skip to main content
Context is a global object that provides access to the document being processed, its fields, and the parameters of the enclosing transaction. Set CheckSucceeded to indicate whether the rule passed.

Usage

A rule reads fields through Context, checks them, and reports the result by setting CheckSucceeded and ErrorMessage. For example, fail the rule with a custom message when the Total field is missing or empty:
var field = Context.GetField("Total");

if (!field || !field.Value) {
  Context.CheckSucceeded = false;
  Context.ErrorMessage = "Total field is empty";
}
For more patterns — numeric comparisons, conditional requirements, and table validation — see Sample scripts.

Properties

CheckSucceeded

Type: boolAccess: Read-write Indicates whether the rule condition is fulfilled. Defaults to true. Set it to false if the condition is not met. In that case, the default error message shown to the operator is Error in the rule <rule_name>: <field_name>. To customize the message, set the ErrorMessage property.
An error is generated only when your script sets CheckSucceeded to false. If the script doesn’t set it explicitly, no error is displayed — even if the rule conditions aren’t met.

CurrentField

Type: FieldAccess: Read-only The field checked by the rule. For repeating fields in repeating rules, this is the specific instance being checked by the current call. Returns null if the rule references the document as a whole.

Document

Type: DocumentAccess: Read-only The document for which the rule runs.

ErrorMessage

Type: stringAccess: Read-write Custom message displayed when the script sets CheckSucceeded to false. If unset, the default message is Error in the rule <rule_name>: <field_name>.

Transaction

Type: TransactionAccess: Read-only The current transaction.

Methods

A script can only read fields listed for reading and write fields listed as editable when the rule is set up. Referencing any other field fails the rule with an access error (Attempt to read data from inaccessible field or Attempt to write data to read-only field). See Business rules automation.

GetField

Field GetField(string fieldName);
Gets a Field by name or identifier. Returns null if no field with that name exists. Use the full path to address fields inside a group — for example, BusinessUnit/Address. When used in a repeating rule, GetField sequentially returns each processed field instance. Otherwise, it returns the first instance of a repeating field.
Pass the field name as a string literal, not a variable. The script preprocessor replaces the literal name with the field’s identifier before execution — variables aren’t processed.

GetFields

Field[] GetFields(string fieldName);
Returns all Field objects with the specified name — useful for iterating over every instance of a repeating field, including every cell in a table column. Returns null if no field with that name exists.
Same preprocessor constraint as GetField: pass a string literal, not a variable.

GetCatalogRecord

Record GetCatalogRecord(string catalogId, string externalId);
Gets a Record from a data catalog (external database). Use this method to compare document field values against catalog field values.
Available only if the catalog has a record identifier configured (for example, a vendor identifier).

SkillParameter

SkillParameter SkillParameter(string ParameterName);
Gets a SkillParameter by name. Read its value from the returned object’s Value property — for example, Context.SkillParameter("Threshold").Value.
Available only if the Document skill has at least one parameter.

Object model

Full JavaScript object reference for use in Advanced Script Rules.

Business rules automation

Add scripted rules to a Document skill, configure readable and writable fields, and reference table columns.

Field

The Field object — inspect and modify a document field during rule execution.

Sample scripts

Working JavaScript samples for common Advanced Script Rule scenarios.