Skip to content

Routes

A route connects one workflow step to the next and carries a condition. When a step finishes, the workflow engine evaluates the step's routes and sends the work item along the first route whose condition is true. If none is true, the work item takes the step's default route.

Use a route to decide where a work item goes, on values that are already on the work item. Use a Custom Step to calculate those values: a route can read, but it cannot change the work item.

At a glance

  • Runs On the workflow worker, in V8, when a step finishes and when a hold on the step is released.
  • Language A JavaScript expression, a no-code Expression, or a global variable that holds a JavaScript expression.
  • Authored in The Workflow designer: select the connection between two steps, then Edit in the Route section of the ribbon.
  • Can reach work-item metadata, documents, hold release information and global variables. Read only. No network.
  • Best for Branching on a value a step wrote: an approval level, an API status code, a validation result, how a task ended.

How a step picks its route

graph TD
  A["Step finishes, or a hold is released"] --> B["Evaluate every custom route, one engine, 10 s in total"]
  B --> C{"Error Work Item error, or time ran out?"}
  C -->|No| D{"Any route true?"}
  D -->|Yes| E["Follow the first true route, in stored order"]
  D -->|No| F{"Default route?"}
  F -->|Yes| G["Follow the default route"]
  F -->|No| H["Leave the workflow, or return to the parent workflow"]
  C -->|Yes| I{"Default route?"}
  I -->|Yes| G
  I -->|No| J["Work item goes into an error state"]
  1. The engine evaluates every custom route of the step. It does not stop at the first true route.
  2. The work item follows the first route, in the step's stored route order, that is true. Do not depend on that order: write conditions that cannot be true at the same time.
  3. If no route is true, the work item follows the default route.
  4. If no route is true and the step has no default route, the work item leaves the workflow at that step. In a sub-workflow, it returns to the parent workflow.

Where you author it

  1. Open the Workflow app, then Workflows, then open the workflow. You need permission to edit it (feature Create Workflows or Manage All Workflows).
  2. Draw a connection from one step to another. The connection is a route.
  3. Select the route. The ribbon has a Route section with Edit, Make Default, Make Custom and Remove. You can also double-click a custom route to edit it.
  4. In the Edit Route dialog, set the Route Name, the Route Exception Behavior and the Route Definition.
  5. To pick the route type, select the gear icon next to Route Definition: Expression, Javascript or Global Variable. Javascript is the default.

A step has at most one default route. The default route has no condition.

Runtime contract

Item Value
Engine V8. All routes of one step share one engine instance for one evaluation.
Runs when The step finishes, and when a hold on the step is released.
Timeout 10 seconds for all routes of the step together.
Network access None.
Objects in scope workItem (alias WorkItem) and GlobalVariables. No builder, batch, helper or console.
Result The value of the last expression, converted to true or false.
Global variable version The version current when the work item was last submitted to the workflow. In a sub-workflow, the version current when it entered the sub-workflow.

Error behavior

Each route has a Route Exception Behavior:

Setting What happens when this route's condition throws
Continue, Assume False (the default) The route counts as false. The other routes still decide.
Error Work Item The engine discards the results of all routes of the step. The work item takes the default route if the step has one. If not, the work item goes into an error state.

If the 10-second limit is reached, the engine treats it like an Error Work Item error, whatever the setting.

The work item object

Routes see the work item as JSON. The property names differ from the Custom Step batch object.

Property Type
workItem.WorkItemId string (GUID). Not BatchId.
workItem.Name string. Not BatchName.
workItem.Metadata[bucket][key] string
workItem.Documents[] DocumentId, Metadata[bucket][key], Files[] (Type, Name, Extension), Pages[] (PageId, Index, Metadata, OriginFileName)
workItem.ReleaseInfo Present only when the routes run because a hold was released.

All metadata values are strings. Bucket and key names are case-sensitive. A missing bucket is undefined, so workItem.Metadata.Index.Total throws when the work item has no Index bucket.

workItem.ReleaseInfo has:

  • ReleaseReasonDesc: one of TasksCompleted, TasksPartiallyCompleted, TasksDeleted, ReleasedByInteractionsService, ReleasedByPortal, PortalTaskDeleted, ReleasedByApi, ReleasedByWebIndex, ReleaseHoldAndMarkIndexed.
  • ReleasedByUser: an internal identifier of the caller that released the hold. For task releases it is InteractionsService. It is not a user display name. Do not route on it.
  • Messages: a string dictionary from the action that released the hold. It can be null.

GlobalVariables.Get(name) returns the variable's value as a string. A missing variable throws Global variable {name} was not found.

Secret variables are readable from routes

GlobalVariables.Get returns the value of a variable marked secret, in Javascript routes, Global Variable routes and Expression routes that compare to a global variable. A route cannot write the value anywhere, but a Custom Step or Custom Event step that copies it into metadata or an event exposes it. Read a secret only to compare it, and never copy it.

Route types

Javascript

The route evaluates your script and converts the result to a boolean. The result is the value of the last expression in the script.

  1. Write one expression, or wrap the logic in a function that you call at once and that returns true or false.
  2. Do not use a top-level return. It is a syntax error.
  3. Guard every bucket before you read a key from it.
  4. Declare variables inside your function. All routes of the step share one engine, so a global that one route sets is visible to the next route.
Javascript route: Over Review Limit
(function () {
  var index = workItem.Metadata["Index"] || {};
  var total = parseFloat(String(index["InvoiceTotal"] || "0").replace(/[^0-9.\-]/g, "")) || 0;
  var limit = parseFloat(GlobalVariables.Get("ReviewLimit"));
  return total > limit;
})()

Expression

An Expression route compares work-item metadata without code. It reads workItem.Metadata[Bucket][Field] only, never document metadata.

Variables

Each variable has a Variable Name, a Bucket Name (the list offers General, Index and Task), a Field Name (the metadata key) and a Data Type. The engine converts the string value before it compares:

Data Type Conversion
Text No conversion. Comparisons are case-sensitive.
Boolean true when the value, lowercased, is "true".
Date new Date(value). Use ISO dates such as 2026-10-01.
Decimal Number(value). "$1,200.00" becomes NaN.
Integer parseInt(value).

Conditions

Each condition picks a variable, an operator and a value. The value is a Static Value, a Local Variable (another variable of the route) or a Global Variable.

Data Type Operators
Text Equals, Does Not Equal, Contains, Does Not Contain, Starts With, Does Not Start With, Ends With, Does Not End With
Boolean Equals, Does Not Equal
Date Equals, Does Not Equal, Is Before, Is On Or Before, Is After, Is On Or After
Decimal, Integer Equals, Does Not Equal, Is Less Than, Is Less Than Or Equal To, Is Greater Than, Is Greater Than Or Equal To

The dialog shows And and Or buttons on the second and later condition rows, and lets you add groups.

A condition on a bucket or key that does not exist throws or compares as false. With Continue, Assume False, the route is false.

Known issue: compound Expression routes

Expression routes with more than one condition evaluate wrong.

  • Two conditions joined by Or behave as And. The editor hides the operator on the first row, and that hidden operator is always And. The engine joins each row to the next row with the operator stored on the first of the two rows. So it uses the hidden And and ignores the Or you selected on row 2. A work item that matches only one condition takes the default route.
  • Three or more conditions. Only the last two conditions decide the result, and the operator between them is not the one the editor shows there. Groups made with Add Group have no effect.

Expression routes are safe only with one condition, or with two conditions joined by And. For anything else, use a Javascript route.

Javascript equivalents

The Javascript equivalents of common compound conditions. Each reads work-item metadata only, like the Expression route it replaces.

Javascript route: A Or B
// Region is West, or the vendor is new.
(function () {
  var index = workItem.Metadata["Index"] || {};
  return index["Region"] === "West" || index["VendorStatus"] === "New";
})()
Javascript route: A And B And C
// Total over the limit, and the vendor is new, and the invoice is not marked urgent.
(function () {
  var index = workItem.Metadata["Index"] || {};
  var total = parseFloat(String(index["InvoiceTotal"] || "").replace(/[^0-9.\-]/g, ""));
  var limit = parseFloat(GlobalVariables.Get("ReviewLimit"));
  return total > limit
    && index["VendorStatus"] === "New"
    && String(index["Urgent"] || "").toLowerCase() !== "true";
})()
Javascript route: (A Or B) And C
// (Region is West or East) and the total is at least 5000.
(function () {
  var index = workItem.Metadata["Index"] || {};
  var region = index["Region"] || "";
  var total = parseFloat(String(index["InvoiceTotal"] || "").replace(/[^0-9.\-]/g, "")) || 0;
  return (region === "West" || region === "East") && total >= 5000;
})()

Parentheses decide the grouping, exactly as written. An unreadable total becomes NaN, and every comparison with NaN is false.

Global Variable

The route reads a global variable and evaluates its value as a JavaScript expression, with the same objects as a Javascript route. Use it when many workflows share one condition and you want to change it in one place. The variable must exist, or the route throws.

Example value of a global variable named IsWestRegion:

Global variable IsWestRegion (data type Javascript)
(workItem.Metadata["Index"] || {})["Region"] === "West"

Rules

  1. Guard every bucket: (workItem.Metadata["General"] || {})["RoutingPath"].
  2. Compare strings exactly. "Yes" === "yes" is false. Parse numbers with parseFloat after you strip $ and ,.
  3. Route on work-item values. A value a Custom Step set per document is not in workItem.Metadata. Ask the Custom Step to write a work-item value with builder.SetBatchMetadata, which works for Expression routes too.
  4. Use an Expression route only for one condition, or two conditions joined by And. Use Javascript for everything else.
  5. Write conditions that cannot be true at the same time, and make the "everything else" path the default route.
  6. Declare variables inside a function. Globals leak from one route to the next in the same step.
  7. Keep it cheap. All routes of a step share 10 seconds.
  8. Read a secret global variable only to compare it.

Gotchas

Mistakes that bite

  • Every work item takes the default route. The value is on the documents, but routes read work-item metadata. Set the value with builder.SetBatchMetadata in the Custom Step.
  • An Or route never matches one-sided cases. An Expression route with two conditions joined by Or behaves as And. Rewrite it as a Javascript route.
  • The route never matches a number. Metadata is text. In a Javascript route, parse with parseFloat and strip $ and , first. In an Expression route, store a clean number.
  • The route never matches although the value looks right. Check the case of bucket and key names. Index.NeedsReview and Index.needsReview are different keys.
  • A route on ApiResults never runs after a failed call. A failed Call External API step stops the work item before routes run. Set the step's Error Behavior to Continue.
  • workItem.BatchId or workItem.BatchName is undefined. Routes use workItem.WorkItemId and workItem.Name, not the Custom Step names. batch does not exist in a route.
  • OcrService is suggested in the editor but fails. It is not available when routes run. Do not use it.

Patterns

Route on a value a Custom Step set

Goal: send invoices over a limit to a manager review step.

  1. In the Custom Step, write the decision to the work item:
builder.SetBatchMetadata("General", "ReviewPath", "Manager");
  1. From the Custom Step, draw a route to the manager review step. Set it to Javascript:
Javascript route: Manager Review
(workItem.Metadata["General"] || {})["ReviewPath"] === "Manager"
  1. Make the route to the normal path the default route.

Test it: run one work item that should match and one that should not. Open each in Monitor or Insight and check General.ReviewPath.

A full example is Set a Routing Value from Metadata.

Route on the HTTP status after Call External API

Goal: send a work item to a review step when an external call fails, instead of stopping it.

  1. Edit the Call External API step. Set Error Behavior to Continue. A non-2xx response then evaluates the routes instead of stopping the work item.
  2. Draw the success route with this Javascript condition:
Javascript route: API Call Succeeded
(function () {
  var api = workItem.Metadata["ApiResults"] || {};
  var code = parseInt(api["LastHttpStatusCode"] || "0", 10);
  return code >= 200 && code < 300;
})()
  1. Make the route to the review step the default route.

A stale status code

A timeout or a refused URL writes no status code, so LastHttpStatusCode keeps the value of an earlier call. If the work item can pass the step twice, clear the key first with a Custom Step: builder.SetBatchMetadata("ApiResults", "LastHttpStatusCode", ""). See Call External API.

Route on how a hold was released

Goal: after a task step, send the work item to a cleanup path when someone deleted the task instead of completing it.

On the step that holds the work item, draw a route with this Javascript condition:

Javascript route: Task Deleted
(function () {
  var info = workItem.ReleaseInfo;
  return !!info && info.ReleaseReasonDesc === "TasksDeleted";
})()

Make the normal path the default route. ReleaseInfo exists only when the routes run right after a release, so always check it for null first.

When your own code releases the hold with V1_WorkflowAPI/ReleaseHold (token feature Manage Workflows), ReleaseReasonDesc is ReleasedByApi. The call fails with HTTP 412 and No hold was found for workitem {id} when the work item has no hold, and no routes run.

Copy this into your assistant

Paste the block below into your AI assistant together with the AI Assistant Primer, then describe the decision the route must make and the fields it reads. It is the same contract as this page, written for a model.

Workflow routes context for AI assistants
# Workflow routes: context for AI assistants

You write route conditions for KnowledgeLake workflows. A route decides which path a work
item takes out of a step. Use only the facts in this block. If you need a bucket, field or global
variable name the user has not given, ask for it. Never invent one.

## The runtime contract
- Engine: V8. All routes of one step share one engine and 10 seconds in total.
- Runs: when the step finishes, and when a hold on the step is released.
- Every custom route of the step is evaluated. The work item follows the first true route in the
  step's stored order, else the default route. With no true route and no default route, the work
  item leaves the workflow at that step (a sub-workflow returns to its parent). Conditions must
  not overlap: do not depend on order.
- A route that throws counts as false with Route Exception Behavior "Continue, Assume False" (the
  default). With "Error Work Item", any error discards all route results: the work item takes the
  default route, or errors when there is none. A 10-second timeout behaves like "Error Work Item".
- No network, no console, no builder, no batch, no helper. A route cannot change the work item.
- No top-level return. The result is the value of the last expression, converted to a boolean.

## Objects
- workItem (also WorkItem): WorkItemId, Name, Metadata[bucket][key], Documents[] (DocumentId,
  Metadata, Files[] with Type/Name/Extension, Pages[] with PageId/Index/Metadata/OriginFileName).
  Not BatchId or BatchName: those are Custom Step names. All metadata values are strings.
- workItem.ReleaseInfo: only right after a hold release, else absent. ReleaseReasonDesc is one of
  TasksCompleted, TasksPartiallyCompleted, TasksDeleted, ReleasedByInteractionsService,
  ReleasedByPortal, PortalTaskDeleted, ReleasedByApi, ReleasedByWebIndex,
  ReleaseHoldAndMarkIndexed. ReleasedByUser is an internal caller id, not a name. Messages may
  be null.
- GlobalVariables.Get("Name"): returns a string. Throws "Global variable Name was not found." for
  a missing one. It also returns secret variables: compare them, never expose them.
- OcrService appears in the editor's suggestions but does not exist at run time. Never use it.

## Route types
- Javascript: your expression. Use it for anything beyond one condition or two conditions
  joined by And.
- Expression: no code. Variables (Bucket Name, Field Name, Data Type Text, Boolean, Date,
  Decimal or Integer) read work-item metadata only. Known issue: two conditions joined by
  Or are evaluated as And (the hidden first-row operator is always And and the engine uses it);
  with three or more conditions only the last two decide and groups are ignored. Only one
  condition, or two joined by And, is safe. Otherwise recommend a Javascript route.
- Global Variable: the variable's value is evaluated as a Javascript expression with the same
  objects. Use it when many workflows share one condition.

## Rules
1. Guard every bucket: (workItem.Metadata["General"] || {})["RoutingPath"].
2. Every value is a string. "Yes" === "yes" is false. Numbers: parseFloat after stripping $ and ,
   with String(x || "").replace(/[^0-9.\-]/g, "").
3. Values a Custom Step set per document are not in workItem.Metadata. Read
   workItem.Documents[i].Metadata, or ask for the Custom Step to write a work-item value with
   builder.SetBatchMetadata (simpler, and Expression routes can use it).
4. A failed Call External API step stops the work item before routes run, unless the step's
   Error Behavior is Continue. A route on ApiResults.LastHttpStatusCode needs Continue.
5. A timeout or a refused URL writes no status, so LastHttpStatusCode can be stale.
6. Declare variables inside a function. Globals leak between routes of the same step.
7. Plain ES5 style: var, function, no template literals, no arrow functions.

## Example
```javascript
// Route "Needs Manager Review": from "Check Invoice" to "Manager Review".
// Reads work item Index.InvoiceTotal and Index.VendorStatus, global variable ReviewLimit.
// Make the route to "Auto Approve" the default route.
(function () {
  var index = workItem.Metadata["Index"] || {};
  var total = parseFloat(String(index["InvoiceTotal"] || "").replace(/[^0-9.\-]/g, ""));
  var limit = parseFloat(GlobalVariables.Get("ReviewLimit"));
  return (total > limit) || index["VendorStatus"] === "New";
})()
```

## Output
Produce one route condition: one expression, or (function () { ...; return true or false; })().
Start with a comment: which step the route leaves from, where it goes, what it reads, and which
route should be the default. Then give the setup steps: Workflow designer, select the connection,
Route section of the ribbon, Edit, gear next to Route Definition, Javascript, paste, set the Route
Exception Behavior, save, and which route to Make Default. Then a test: one work item that should
match and one that should not, and which metadata to check in Monitor or Insight.