1. Context & Environment
Every business process runs with a single global object in scope: context. It carries the record that triggered the process, the caller's identity, your app's environment variables, and the function library itself.
console.log(context.slug); // "invoices"
console.log(context.triggerType); // "AfterCreate"
console.log(context.record.ID); // 84context is always available — there is nothing to import or construct. Alongside it you also get the globals log, console, and inputs.
Context properties
Prop
Type
Legacy process code frequently used context.user.id. That property does not exist. The caller's ID lives at context.claims.userId.
What record and updates contain
The two most common mistakes are reading context.record.ID on a BeforeCreate (the row has no ID yet) and expecting updates to be a full record (it is only the incoming payload).
| Trigger type | context.record | context.updates |
|---|---|---|
BeforeCreate | Incoming values — no ID yet | Same incoming values |
AfterCreate | The saved record, fully expanded | Payload plus system fields |
BeforeUpdate | The record as it was before the update | Only the fields being changed |
AfterUpdate | The record after the update | Only the fields that were changed |
BeforeDelete / AfterDelete | The record as it was before deletion | null |
BeforeFetch / AfterFetch | null — see context.operation | null |
Scheduled / Manual | Whatever was passed in, otherwise empty | null |
Webhook | Request body — also on context.req.body | null |
Mutating context.record inside a Before* process changes what gets written to the database. Several processes on the same event run one after another and share the same context, so each one sees the previous one's edits.
Record shape
Records are flat objects keyed by column name in PascalCase.
const invoice = await context.functions.getById("invoices", 84);
invoice.ID; // 84
invoice.Amount; // 1500
invoice.CreateDate; // "2026-03-12T10:24:00.000Z" — a string
invoice.CreateUser.FullName; // "John Smith" — lookups arrive expandedThree things to know:
- Dates are strings, never
Dateobjects. A date-only value comes back as"2026-03-12"; a timestamp as"2026-03-12T10:24:00.000Z"in UTC. Wrap innew Date(...)if you need to do arithmetic. - Lookup fields arrive expanded. A lookup column holds an object with the referenced row's key and display fields rather than a bare foreign key, so
CreateUserandModifyUserread as{ ID, FullName }. create()returns a lowercaseid, while records everywhere else use uppercaseID. This one inconsistency causes a lot of lost time.
Every entity carries six system fields — ID, CreateDate, CreateUser, ModifyDate, ModifyUser, and SystemStatusID. They are managed by the platform: if you include them in a create or update payload they are silently stripped.
context.claims
Who triggered the run.
Prop
Type
Runs with no human behind them get a different shape. Scheduled and manually started processes receive { system: true, manualExecution: true }, and route-triggered processes receive { system: true, routeExecution: true } — so always guard before reading a user field:
if (context.claims.system) {
log("Running unattended");
} else {
log("Started by user " + context.claims.userId);
}context.env
Your application's variables, flattened into one map. Use it for API keys and per-environment endpoints instead of hardcoding them in process code.
const response = await context.functions.http({
url: context.env.CRM_BASE_URL + "/contacts",
headers: { "Authorization": "Bearer " + context.env.CRM_API_KEY }
});Private variables override public ones, which override plain variables. If the variables cannot be loaded, context.env is an empty object rather than an error — so a missing key reads as undefined and your process keeps running with a broken URL. Check explicitly when it matters:
if (!context.env.CRM_API_KEY) throw new Error("CRM_API_KEY is not configured");context.operation
Set only on BeforeFetch and AfterFetch, where there is no single record. It describes the query being run: slug, skip, take, filter, searchTerm, and sort, plus resultCount on AfterFetch.
/** @event afterFetch */
log("Returned " + context.operation.resultCount + " rows for " + context.operation.slug);context.req
Set only on processes exposed at a route.
/** @event webhook */
const payload = context.req.body;
const signature = context.req.headers["x-signature"];
if (!signature) throw new Error("Missing signature header");
await context.functions.create("webhookevents", { Payload: JSON.stringify(payload) });Logging
Prop
Type
log("Processing invoice " + context.record.ID);
console.warn("Amount exceeds approval limit");Objects are serialized for you, so log(context.record) prints the whole record.
In a debug session console.warn and console.error are not bound. Calling either throws a TypeError that will not reproduce during a normal run. Stick to console.log or log in code you plan to step through.