Skip to content

Intuitive AI Script Reference

This page lists every object a Custom Condition, Custom Document Condition, Custom Action or Custom Document Action script can use. The names are case-sensitive.

For when each script runs and how its result is scored, see Custom Refiners and Custom Actions.

At a glance

  • Engine V8 (Microsoft ClearScript) on the Intuitive AI worker
  • Globals state, services, result, Enumerable, EnumerableHelpers
  • Not here console, fetch, require, GlobalVariables, batch, builder
  • Host values .NET objects. Use Length() and [i], not .length.

Summary

Object What it is
state The page or document under test, the work item snapshot, and per-rule caches
services OCR and page-dimension services. Calls are synchronous.
result Where the script reports its confidence and, for actions, its Index writes
Enumerable .NET System.Linq.Enumerable
EnumerableHelpers Adds Length(), Where(), Get(), Set(), Remove(), GetKeys() and GetValues() to host collections

Every member, with a link to its entry:

Member Scripts What it gives you
state.DocumentId Page Id of the document that holds the page
state.PageId Page Id of the page under test
state.BatchProjection Page, document Read-only work item snapshot
state.BatchToken Page Internal token. Do not read it.
state.TemplateZones Page Zones on the model document
state.KnownPage Page The model page under comparison
state.KnownSubclass Page, document The subclass under test
state.UserCache Page Scratch space for one rule on one page
state.OcrCache Page Zone OCR from earlier OCR actions
state.OmrCache Page Checkbox results from OMR actions
state.ConditionZoneDetectionCache Page Zone results from earlier conditions
state.ActionZoneDetectionCache Page Zone results from earlier actions
state.OriginalDocumentId Document Id of the document under test
state.PageIds Document Page ids, in order
state.KnownClass Document The class under test
state.Classification Document The engine's classification result
GetPageOcr Page OCR of the current page
GetZoneOcr Page OCR of one template zone
GetRegionOcr Page OCR of any rectangle
GetDocumentOcr Document OCR of the document
GetBatchPageDimensions Page Page image size
OCR result All The shape every OCR method returns
result.SetResult All Sets the confidence
result.SetDocumentMetadata Actions Queues an Index write
Collection helpers All Length(), [i], Where() and dictionary methods

state in a page script

A Custom Condition and a Custom Action get this state.

  • Custom Condition Gets the live object.
  • Custom Action Gets a copy. Changes it makes are not seen by later actions, except changes to state.UserCache.

state.DocumentId

The id of the document that holds the page under test.

  • Type Guid (a .NET value)
  • As text Use .ToString()
var docId = state.DocumentId.ToString();

state.PageId

The id of the page under test.

  • Type Guid
  • As text Use .ToString()
var pageId = state.PageId.ToString();

state.BatchProjection

A read-only snapshot of the work item as the engine received it. "Batch" is the older name for a work item.

  • Type object with Id, Name, Metadata and Documents
  • Documents Each document has Id, Index, Metadata and Pages
  • Metadata A dictionary of buckets. Each bucket is a dictionary of string values.
  • Note Values that actions write during this run are not in the snapshot.
function getDocumentValue(bucket, key) {
    var docs = state.BatchProjection.Documents;
    for (var i = 0; i < docs.Length(); i++) {
        if (docs[i].Id.Equals(state.DocumentId)) {
            if (!docs[i].Metadata.ContainsKey(bucket)) { return null; }
            return docs[i].Metadata.Get(bucket).Get(key);
        }
    }
    return null;
}

state.BatchToken

An internal token that the service overloads pass through. Do not read it.

state.TemplateZones

The zones drawn on the model document.

  • Type List of Zone
  • Zone members Id, KnownPageId and RectangleCoordinates
  • Note Zones have no names. Pick them by KnownPageId or by position.
var zonesOnThisModelPage = state.TemplateZones.Where(function (z) {
    return state.KnownPage && z.KnownPageId.Equals(state.KnownPage.Id);
});

state.KnownPage

The model page the engine is comparing with.

  • Type object with Id, Position, Width and Height
  • Null when The script runs in a class-level refiner

state.KnownSubclass

The subclass under test.

  • Type object with Id and Name
  • Null when The script runs in a class-level refiner
  • Note The editor completion does not list it.
var subclassName = state.KnownSubclass ? String(state.KnownSubclass.Name) : "";

state.UserCache

Scratch space shared by the conditions and actions of one rule on one page.

  • Type Writable dictionary
  • Methods Set(key, value), Get(key) (null when missing), ContainsKey(key), Remove(key)
state.UserCache.Set("vendorScore", "0.8");

state.OcrCache

Zone OCR that OCR actions stored in this rule on this page.

  • Type Dictionary of OCR results. See OCR result.
  • Keys Each OCR action's Property: name
var total = state.OcrCache.ContainsKey("Invoice Total") ? String(state.OcrCache.Get("Invoice Total").Text) : "";

state.OmrCache

OMR (checkbox) results that OMR actions stored in this rule on this page.

state.ConditionZoneDetectionCache

Zone results from conditions that already ran in this rule, keyed by condition id. A Regex Anchor stores its moved zone here.

state.ActionZoneDetectionCache

Zone results from actions that already ran in this rule, keyed by action id.

state in a document script

A Custom Document Condition and a Custom Document Action get this state.

No TemplateZones

The document state has no TemplateZones, even though the editor completion lists it.

state.OriginalDocumentId

The id of the document under test.

  • Type Guid
  • As text Use .ToString()
var docId = state.OriginalDocumentId.ToString();

state.PageIds

The pages of the document, in order.

  • Type List of Guid
  • Access Use Length() and [i]
var pageCount = state.PageIds.Length();

state.BatchProjection (document)

The same read-only work item snapshot as in a page script. See state.BatchProjection.

state.KnownClass

The class under test.

  • Type: object with Id and Name
var className = String(state.KnownClass.Name);

state.KnownSubclass (document)

The subclass under test.

  • Type: object with Id and Name, or null

state.Classification

The engine's classification result for the document. Read it only to inspect; its shape is internal.

services

All calls are synchronous. OCR results are cached for the run, so a second call for the same page is cheap.

Every OCR method takes an optional last argument ocrProvider (string). Leave it out to use the tenant's OCR engine.

GetPageOcr

services.OcrService.GetPageOcr(state)

Returns the OCR of the current page.

  • Scripts Page scripts only
  • Parameters state (the page state)
  • Returns An OCR result
var text = String(services.OcrService.GetPageOcr(state).Text || "");

GetZoneOcr

services.OcrService.GetZoneOcr(state, zone)

Returns the OCR of one template zone on the current page.

  • Scripts Page scripts only
  • Parameters state; zone (an item of state.TemplateZones)
  • Returns An OCR result
var zoneText = String(services.OcrService.GetZoneOcr(state, state.TemplateZones[0]).Text || "");

GetRegionOcr

services.OcrService.GetRegionOcr(state, rectangleCoordinates)

Returns the OCR of any rectangle on the current page.

  • Scripts Page scripts only
  • Parameters state; rectangleCoordinates (for example a zone's RectangleCoordinates)
  • Returns An OCR result
var regionOcr = services.OcrService.GetRegionOcr(state, state.TemplateZones[0].RectangleCoordinates);

GetDocumentOcr

services.OcrService.GetDocumentOcr(state, maxPagesToOcr)

Returns the OCR of the document.

  • Scripts Document scripts only
  • Parameters state (the document state); maxPagesToOcr (number, optional)
  • Page limit Default 20, capped at 100
  • Returns An OCR result
var docText = String(services.OcrService.GetDocumentOcr(state, 5).Text || "");

GetBatchPageDimensions

services.ImageRetriever.GetBatchPageDimensions(state)

Returns the size of the current page image.

  • Scripts Page scripts only
  • Returns An object with Width and Height in pixels
var size = services.ImageRetriever.GetBatchPageDimensions(state);

OCR result

Every OCR method returns this shape.

Property What it holds
Text All recognized text, as a string with line breaks between lines. Wrap it in String(...) before you use JavaScript string methods.
Confidence The OCR confidence, a number from 0 to 1
Bounds The rectangle of the text: X, Y, Width, Height in pixels
ChildrensLevel The level of Children, for example page, line, word or character
Children The child OCR results, each with the same shape. Use Length() and [i].
var ocr = services.OcrService.GetPageOcr(state);
for (var i = 0; i < ocr.Children.Length(); i++) {
    var line = ocr.Children[i];
}

result

result.SetResult

result.SetResult(confidence)

Sets the confidence of the condition or action.

  • Parameters confidence (number from 0 to 1; values outside are clamped)
  • Conditions No call means "no opinion" in a page refiner and 0 in a rule.
  • Actions The default is 1.
result.SetResult(0.85);

result.SetDocumentMetadata

result.SetDocumentMetadata(key, value)

Queues a write to the Index bucket of the current document.

  • Scripts Actions only
  • Parameters key (string, the Index field name, exact and case-sensitive); value (string, number or boolean)
  • Returns nothing. The write is applied after the engine resolves all rules.
  • Formatting Numbers and booleans are formatted on the server. A boolean becomes True or False.
  • Advice Pass strings you formatted yourself.
result.SetDocumentMetadata("Invoice Total", (1234.5).toFixed(2));

Collection helpers

Values from state and services are .NET objects, not JavaScript arrays. EnumerableHelpers adds these methods.

Method What it does
x.Length() Number of items in a list
x[i] One item of a list or .NET array
x.Where(predicate) Items that match a predicate
d.ContainsKey(key) True when a dictionary has the key
d.Get(key) Value for a key, or null
d.Set and d.Remove Change a writable dictionary
d.GetKeys and d.GetValues Keys or values as a .NET array
Enumerable Static LINQ calls

x.Length()

Returns the number of items in any list.

var zoneCount = state.TemplateZones.Length();

x[i]

Returns one item of a list or a .NET array.

var firstZone = state.TemplateZones[0];

x.Where()

x.Where(predicate)

Returns the items for which predicate(item) is true.

  • Parameters predicate (a function that takes one item)
  • Returns A .NET array. Use Length() and [i] on it.

See the example under state.TemplateZones.

d.ContainsKey()

d.ContainsKey(key)

Returns true when a dictionary has the key.

var hasTotal = state.OcrCache.ContainsKey("Invoice Total");

d.Get()

d.Get(key)

Returns the value for the key, or null when the key is missing.

var score = state.UserCache.Get("vendorScore");

d.Set and d.Remove

d.Set(key, value) and d.Remove(key)

Change a writable dictionary, such as state.UserCache.

state.UserCache.Remove("vendorScore");

d.GetKeys and d.GetValues

d.GetKeys() and d.GetValues()

Return the keys or the values of a dictionary as a .NET array.

var cachedKeys = state.UserCache.GetKeys();

Enumerable

.NET System.Linq.Enumerable, for static calls such as Enumerable.Count(state.TemplateZones).

Not available

  • No console. Nothing the script prints is kept. See Debugging Intuitive AI Scripts.
  • No network: no fetch, XMLHttpRequest, require or import.
  • No metadata reads of this run's writes, and no writes outside the Index bucket of the current document.
  • No page images or file bytes. You get OCR text and page dimensions.
  • No workflow objects: GlobalVariables, batch and builder belong to the Custom Step.