What This Table Is

The wf_context table stores runtime execution instances of ServiceNow workflows. Each record represents an active workflow execution—tracking where the workflow is in its flow, what data it's operating on, and any errors that occurred during processing. This is the runtime state table that lets you debug why workflows get stuck, monitor execution progress, and understand what data workflows are working with.

The Workflow module owns this table and uses it to orchestrate all workflow execution. When a workflow starts—whether triggered by a business rule, scheduled job, or manual execution—ServiceNow creates a wf_context record to track that execution instance. The workflow engine continuously updates this record as activities complete, variables change, and the workflow progresses through its defined flow.

This table doesn't extend any parent table—it's a standalone system table. The related wf_context_log table captures the execution history and activity transitions for each context record, providing a detailed audit trail of workflow execution.

In large enterprises, this table can contain thousands of records during peak processing hours, especially with automated workflows processing incident assignments, approvals, and integrations. Records typically clean themselves up when workflows complete, but stuck workflows will leave context records active indefinitely. Performance is generally good since most queries filter by workflow or table fields, which are indexed.

When You'll Script Against This Table

Most developers query wf_context from Script Includes when building workflow monitoring tools, Background Scripts for debugging stuck workflows, and Business Rules that need to check if workflows are currently running against specific records. You'll also hit this table in Scheduled Jobs that clean up orphaned workflow contexts or send alerts about long-running workflows.

Access requires the workflow_admin role for full read/write access, though admin can also access these records. The workflow engine itself runs in elevated context, but custom scripts need proper permissions to query or modify workflow contexts.

  • Debug stuck workflows by finding contexts in waiting or error states
  • Monitor workflow execution progress by checking current activity positions
  • Prevent duplicate workflow execution by checking for existing active contexts
  • Extract workflow variable values from the serialized scratchpad data
  • Build workflow performance analytics by analyzing execution duration
  • Cancel or restart workflows programmatically by updating state values
  • Create workflow monitoring dashboards showing active execution counts by workflow type

Table Gotchas

⚠️

The scratchpad field stores workflow variables as XML, not JSON. Don't try to parse it with JSON methods—you'll need to use the Workflow API or parse the XML structure manually.

⚠️

State values are stored as integers, not strings. Use state != 3 instead of state != 'Finished' when querying for active workflows.

  • The document_id field stores the sys_id of the record the workflow is operating on, but it's a string field, not a reference—you can't dot-walk from it
  • Workflows can have multiple active contexts if they're designed with parallel flows—don't assume one workflow per record
  • The started timestamp uses the system timezone, not user timezone—factor this in for time-based queries
⚠️

Never update wf_context records directly unless you know what you're doing. The workflow engine expects specific state transitions—incorrect updates can corrupt workflow execution.

  • Performance trap: querying by document_id without filtering by table can be slow on large instances
Free Newsletter

Enjoying this? Get one deep-dive per week.

Join 1,000+ ServiceNow pros — scripts, GlideRecord patterns, Flow Designer techniques, and career moves. Free.

No spam · Unsubscribe anytime

The wf_workflow table contains the workflow definitions that these contexts execute against. The workflow field in wf_context references this table to identify which workflow definition is being executed. You'll often join these tables to get workflow names, descriptions, and configuration details.

The wf_context_log table provides detailed execution history for each workflow context, showing activity transitions, timing, and error details. The wf_activity table defines the individual activities that make up workflows, and contexts reference current activities through the current_activity field.

Since workflows operate on various record types, you'll frequently join wf_context with business tables like incident, change_request, or sc_req_item using the document_id field to understand what records have active workflows and their current processing state.