Skip to content

The Work Item Model

Every script and integration in KnowledgeLake reads or writes the same object: the work item. A work item is one unit of work that moves through a workflow, for example one upload of three invoices. This page gives its shape, the rules every surface follows, and the name each surface uses for the same value.

At a glance

  • Shape A work item holds documents, a document holds files and pages.
  • Metadata At three levels (work item, document, page), each in named buckets of keys.
  • Values Every value is a string. Names are case-sensitive.
  • Routes Expression routes read work-item metadata only.
  • Older name "batch". You still see it in names such as batch, BatchId and SetBatchMetadata. It means the same thing.

The shape

graph TD
  WI["Work item: WorkItemId, Name"] --> WM["Work item metadata"]
  WI --> DOC["Documents"]
  DOC --> DM["Document metadata"]
  DOC --> FIL["Files: Input and Output"]
  DOC --> PG["Pages"]
  PG --> PM["Page metadata"]
  WM --> BK["Bucket, for example Index"]
  BK --> KEY["Key and string value, for example Vendor = Acme Corp"]

The same structure as a script sees it:

Work item shape
Work item
  WorkItemId, Name
  Metadata[bucket][key]            work-item metadata (routes read this)
  Documents[]
    DocumentId
    Metadata[bucket][key]          document metadata (index fields live here)
    Files[]                        Type (Input or Output), Name, Extension
    Pages[]
      PageId, Index, OriginFileName
      Metadata[bucket][key]        page metadata

Metadata exists at three levels: the work item, each document, and each page. Each level has the same structure: named buckets, and inside each bucket, keys with values.

Buckets

Bucket What it holds
Index The indexed fields. On a document, these are the fields the index panel shows and that the release step writes to the repository.
General Other working values. The platform keeps some values here, for example a document's ContentTypeId, DocURL and KL_IsReleased after release, and CS5MarkedAsIndexed after Start QC Task runs behaviors. Put your own working values here.
System Platform state. Do not write to it. A Custom Step write to System is dropped with no error.
ApiResults Written by the Call External API step on the work item: LastHttpStatusCode, and the key you name in Response Metadata Key.
Trigger Written when a trigger form starts a work item: one key per form field, on the work item.

The platform uses other buckets for its own state. Do not write to a bucket that is not in this table unless a page tells you to.

Rules

  1. Every value is a string. A number is "18330.34". A date is "2026-10-01". A check box is "true" or "false". Convert before you do math: parseFloat(String(value || '').replace(/[^0-9.\-]/g, '')) || 0. Convert back with toFixed(2) or String(x) when you write.
  2. Bucket and key names are case-sensitive. Index is not index. InvoiceTotal is not invoiceTotal. A key with a space keeps the space.
  3. A missing bucket or key is undefined, not an empty string. Guard each level before you read the next one. A missing bucket makes Metadata['Index']['Vendor'] throw.
  4. Expression routes read work-item metadata only. A value written only on a document does not drive an Expression route. If a route must act on a value, write it to the work item too.
  5. Write through the surface's own write path. A Custom Step writes with builder. The REST API writes with the Upsert...Metadata actions. Changing the object you read does nothing.
Read a value safely (Custom Step)
var index = batch.Metadata['Index'] || {};
var vendor = index['Vendor'] || '';
var total = parseFloat(String(index['InvoiceTotal'] || '').replace(/[^0-9.\-]/g, '')) || 0;
builder.SetBatchMetadata('General', 'CheckedTotal', total.toFixed(2));

Work item, document and page metadata

  • Work item Describes the whole unit of work: a total across documents, a routing flag, the ApiResults from a call, the Trigger form values.
  • Document Describes one document. The index panel and the release to the repository use the document's Index bucket. A document's content type is in its General bucket (ContentTypeId).
  • Page Describes one page. Few integrations need it.

The same key can exist at more than one level with different values. For example, a Custom Step can set Index.NeedsReview on each document for the reviewer, and on the work item for the route.

Documents, files and pages

  • Document One logical document, for example one invoice. It has an id, metadata, files and pages.
  • File A stored file on the document. Type is Input (what came in) or Output (what the platform produced).
  • File bytes Scripts see the file list (Type, Name, Extension), not the file bytes. To read the bytes, call V1_KWorkItemAPI/GetDocumentFile from your own code.
  • Page One page image of the document, in order (Index).

The same value from every surface

Each surface uses its own names for the same data. The table shows how to read the Vendor index field on the work item.

Surface How to read Vendor
Custom Step, Custom Event batch.Metadata["Index"]["Vendor"]
Workflow route (JavaScript) workItem.Metadata["Index"]["Vendor"]
Liquid in a step setting {{ WorkItem.Metadata.Index.Vendor }}
REST API, GetWorkItem Data.Metadata.Index.Vendor in the response
Custom Behavior (document field) panel["Vendor"].RuntimeValue

For a document's value, read it from the documents list:

Surface Document Vendor
Custom Step, Custom Event batch.Documents[i].Metadata["Index"]["Vendor"]
Workflow route (JavaScript) workItem.Documents[i].Metadata["Index"]["Vendor"]
Liquid {% for d in WorkItem.Documents %}{{ d.Metadata.Index.Vendor }}{% endfor %}
REST API, GetWorkItem Data.Documents[i].Metadata.Index.Vendor

A key with a space uses brackets: {{ WorkItem.Metadata["Index"]["Invoice Total"] }} in Liquid, batch.Metadata["Index"]["Invoice Total"] in JavaScript.

Names that differ between surfaces

Value Where it is called what
Work item id batch.BatchId in a Custom Step or Custom Event. WorkItemId in routes, Liquid and the REST API. The WorkItemId header in a Call External API request.
Work item name batch.BatchName in a Custom Step or Custom Event. Name in routes, Liquid and the REST API.
Document id DocumentId in a Custom Step, routes and Liquid. Id in the REST API GetWorkItem response.

Surfaces that do not see the whole work item

  • Behaviors Custom Behaviors and search filter behaviors see only the fields on the panel, not the work item or other documents.
  • Intuitive AI Scripts see the page or document being processed and its OCR text, plus a read-only snapshot of the work item in state.BatchProjection. Actions write Index fields of the current document with result.SetDocumentMetadata(key, value).
  • Custom Event Steps read the whole work item but cannot change it. They write event properties only.
  • Custom Gizmos Get values only through their configuration inputs (which a task layout can map from task inputs) or through gizmo.API.
  • Insight widgets Custom Insight widgets do not see work items. Your endpoint returns the data.