Common JavaScript Errors¶
KnowledgeLake runs your JavaScript in several engines. Each has the standard language, but only the objects KnowledgeLake puts into it. Most errors come from reaching for an object that exists in a browser, in Node.js or in an old sample, but not in the engine your script runs in. This page lists the engines and what they hold, then the errors you see, each with its cause and fix.
At a glance
- Server engines (V8) Custom Step, Custom Event step, JavaScript routes, step setting preprocessors, Custom Behaviors run on the server, Intuitive AI scripts
- Browser engines Custom Behaviors and search filter behaviors (QuickJS), Custom Gizmos (the browser itself)
- Never available outside gizmos
console,fetch,XMLHttpRequest,require,setTimeout,window,document - Every metadata value is a string
Summary¶
| Error | Group |
|---|---|
logger is not defined |
Missing objects |
console is not defined |
Missing objects |
fetch is not defined |
Missing objects |
Context is not defined |
Missing objects |
Papa or setTimeout is not defined |
Missing objects |
| Cannot read properties of undefined | Type and syntax errors |
| X is not a function | Type and syntax errors |
await is only valid in async functions |
Type and syntax errors |
| Unexpected token | Type and syntax errors |
| A Custom Event step fails on a property value | Failures with no clear error |
| Wrong results with no error | Failures with no clear error |
| The script times out | Failures with no clear error |
Which engine runs your script¶
| Surface | Engine and time limit |
|---|---|
| Custom Step (workflow) | V8 on the server. 120 s by default (tenant setting CustomStepTimeout) |
| Custom Event step (workflow) | V8 on the server. 10 s |
| Workflow route, JavaScript type | V8 on the server. 10 s for all routes of one step together |
| Custom Behavior in the index panel | QuickJS in the browser. 5 s |
| Search filter behavior (search panel) | QuickJS in the browser. 1.5 s |
| Custom Behavior run on the server | V8 on the server. 5 s. This happens in the Index Your Documents, Run Indexing Behaviors and Start QC Task steps, and in Search bulk edit. context.app is "worker" there |
| Intuitive AI custom refiner or action | V8 on the server. 5 to 15 min, by script type |
| Custom Gizmo | The user's browser, in a sandboxed frame. No limit set by KnowledgeLake |
All engines support the standard language (ES2015 and later) and its built-in objects: JSON, Math, Number, parseInt, parseFloat, String and Array methods, Date, RegExp, Object, Map, Set. Keep samples plain (var, function); plain code runs the same in V8 and QuickJS.
| Objects | Where they exist |
|---|---|
batch, workItem, builder, helper, GlobalVariables, Papa |
Custom Step |
batch, workItem, builder.SetEventProperty, GlobalVariables |
Custom Event step |
workItem, GlobalVariables |
JavaScript routes |
panel, metadataKvp, builder, context, helper |
Custom Behaviors and search filter behaviors |
state, services, result, Enumerable, EnumerableHelpers |
Intuitive AI scripts |
gizmo, console, fetch, window, document |
Custom Gizmos only |
How an error reaches you¶
- Custom Step, Custom Event The step fails, and Monitor shows
Error in executing Javascript V8.with the engine's error and line. Queuedbuilderchanges are not applied, and a Custom Event writes no event. - Route A route that throws counts as false with the default exception behavior.
- Behavior in the browser The field shows "Behavior Custom Behavior could not be fired." The engine's error is logged in the browser console (F12).
- Gizmo A gizmo logs to the browser console.
graph TD
S["Script throws"] --> A{"Where does it run?"}
A -->|"Custom Step or Custom Event"| M["Step fails, Monitor shows the error"]
A -->|"Route"| R["Route counts as false, next route tried"]
A -->|"Behavior in the browser"| F["Field shows could not be fired, console has the error"]
A -->|"Behavior on the server"| W["Step or bulk edit reports the error"]
Missing objects¶
These are ReferenceError messages: the script uses an object that the engine does not have.
logger is not defined¶
- Message
ReferenceError: logger is not defined(orhttp) - Cause The script came from a Process Designer "Modify Your Metadata" sample.
loggerandhttpbelonged to that activity. - Fix Write diagnostic values to metadata, for example
builder.SetBatchMetadata("General", "StepNote", note). Call outside systems with Call External API or your own endpoint. - Related Custom Step reference
console is not defined¶
- Message
ReferenceError: console is not defined - Cause A browser or Node.js habit. No server or behavior engine has
console. Only Custom Gizmos do. - Fix Write the value to metadata (Custom Step), to an event property (Custom Event) or to a field (behavior), then remove it before you go live.
- Related Debugging Custom Step
var note = "Documents: " + batch.Documents.length + ", Vendor: " + (batch.Metadata["Index"] || {})["Vendor"];
builder.SetBatchMetadata("General", "StepNote", note);
fetch is not defined¶
- Message
ReferenceError: fetch is not defined(orXMLHttpRequest,require) - Cause Server and behavior engines have no network or module access.
- Fix Call outside systems from the workflow with Call External API, then parse
batch.Metadata["ApiResults"]in a Custom Step, or move the work to your own endpoint. - Related Call External API
Context is not defined¶
- Message
ReferenceError: Context is not defined - Cause Old documentation spelled the behavior context with a capital C.
- Fix Use
context.username,context.usergroupsandcontext.app, all lowercase. - On the server
context.usernameis""andcontext.appis"worker". - Related Custom Behaviors reference
Papa or setTimeout is not defined¶
- Message
ReferenceError: Papa is not definedorsetTimeout is not defined - Cause
Papa(CSV parsing) exists only in the Custom Step.setTimeoutexists in no server or behavior engine; scripts run once, top to bottom. - Fix Parse with plain string code, or move the logic to a Custom Step. Remove timers.
- Related Custom Step reference
Type and syntax errors¶
Cannot read properties of undefined¶
- Message
TypeError: Cannot read properties of undefined (reading 'X') - Cause The code reads a property of something that does not exist:
batch.Documents[0]on a work item with no documents, a bucket the item does not have, afind(...)that matched nothing, or the wrong case (doc.metadata,batch.documents,doc.documentId). - In QuickJS The message uses other words.
- Fix Guard each level, as in the example below.
- Related The work item model
function readValue(item, bucket, key) {
var buckets = item && item.Metadata;
var values = buckets && buckets[bucket];
var value = values && values[key];
return value === undefined || value === null ? "" : String(value);
}
batch.Documents.forEach(function (doc) {
if (readValue(doc, "Index", "Vendor") === "") {
builder.SetDocumentMetadata(doc.DocumentId, "General", "ReviewReason", "Vendor missing");
}
});
X is not a function¶
- Message
TypeError: X is not a function - Cause One of the four mistakes below.
- Wrong case
builder.setBatchMetadatadoes not exist;builder.SetBatchMetadatadoes. Everybuildermethod starts with a capital letter. - Other surface A method from another surface.
builder.SetFieldIsVisibleexists only in behaviors,builder.SetBatchMetadataonly in the Custom Step,builder.SetEventPropertyonly in the Custom Event step. - Host value A host value used as an array.
GlobalVariables.Get("Name")returns a string. Split or parse it first. - Shorthand The behavior shorthand
SetChoices, which always fails. - Fix Match the reference for your surface. In behaviors, use
builder.SetFieldChoices(field, choices). - Related Custom Behaviors reference
await is only valid in async functions¶
- Message
SyntaxError: await is only valid in async functions - Cause A Custom Step has no top-level
await, and no asynchronous APIs to wait on. - Fix Remove
awaitandasync. - Related Custom Step introduction
Unexpected token¶
- Message
SyntaxError: Unexpected token - Cause Often a smart quote (
“or’) pasted from a document or a chat window. - From JSON.parse It means the text is not JSON, for example a Call External API response that is an HTML error page.
- Fix Retype the quotes. Check
ApiResults.LastHttpStatusCodebefore you parse, and wrap the parse. - Related Debugging Call External API and functions
var raw = (batch.Metadata["ApiResults"] || {})["FxRate"] || "";
var parsed = null;
try {
parsed = JSON.parse(raw);
} catch (e) {
builder.SetBatchMetadata("General", "StepNote", "FxRate response was not JSON");
}
Failures with no clear error¶
A Custom Event step fails on a property value¶
- Cause
builder.SetEventProperty(key, value)got an object or an array. Event properties are text only. - Fix Pass
String(x)for numbers andJSON.stringify(x)for structures. - Related Custom Event step
Wrong results with no error¶
- Cause One of the four mistakes below.
- Strings Every metadata value is a string, so
"100" > "50"compares text and is false, and"10" + 5is"105". - Booleans A Boolean field reads
"true"or"false", andif ("false")is true. - Queued writes In a Custom Step,
builderwrites apply when the script ends, sobatchstill returns the old value. - Dates
new Date("03/04/2026")is read differently by different engines and locales. - Fix Convert first (
parseFloat(value) || 0), compare Boolean text (value.toLowerCase() === "true"), keep new values in variables or callbuilder.ApplyChanges(), and parse date parts yourself and write dates as2026-03-04. - Related Gotchas
The script times out¶
| Message | Surface |
|---|---|
Error in executing Javascript V8. Javascript timeout limit was exceeded |
Custom Step (120 s) or Custom Event step (10 s) |
Error: Script execution interrupted by host |
Custom Behavior run on the server (5 s) |
| "Behavior Custom Behavior could not be fired." | Custom Behavior in the browser (also for other errors) |
- Cause A loop that never ends, or work that belongs somewhere else.
- Fix Find the loop. Move heavy work to a Custom Step (from a behavior) or to your own endpoint (from a Custom Step).
- Related Error message index