Overview

The Caseblocks scripting environment runs your JavaScript inside a controlled sandbox. Scripts can receive case data, change it, call helpers, and return results. They run from lifecycle hooks, Case Tasks, webhooks, and similar triggers.

Typical flow: read or change payload, optionally call APIs or graphql, then call exit(payload) to save changes or fail(message) to stop with an error.

exit(payload)

Returns the object to Caseblocks. Fields you set on payload are applied to the case when the script succeeds.

fail(message)

Stops processing and surfaces message to the user as a failure.

log(data)

Writes to system logs and to the calling context (for example the Task run log).

delay(ms)

Returns a Promise that resolves after ms milliseconds. Use this instead of setTimeout (not available in the sandbox). Example:

delay(2000).then(function () {
  exit(payload);
});

Available variables

payload

The current case as a plain object. Nested properties mirror your case template fields. If you mutate payload and pass it to exit(payload), those changes are persisted (subject to permissions and validation).

Use log(JSON.stringify(payload)) while debugging if you need to inspect shape and values.

For machine-readable copies of these pages (full Markdown, no HTML chrome), see Documentation for automated clients.


Copyright © 2025 Caseblocks Limited.