OBLYTECH Logo
OBLYTECH Logo

ServiceNow workflow table

ServiceNow stores a workflow across several tables. The workflow record sits in wf_workflow, each published or checked-out edition sits in wf_workflow_version, and each live run is an individual wf_context record. Keeping these apart is why an edit in progress can sit beside the copy that users are still running.

The core tables behind a workflow

Workflow data is spread over a number of tables. These are normally changed through the Workflow Editor rather than edited one row at a time. The core set is below. For the wider concept, see workflow automation in ServiceNow.

Table What it holds
wf_workflow The primary record of each workflow
wf_workflow_version Particular versions of a workflow, published or checked out
wf_context Individual instances of a workflow that is in use
wf_workflow_instance Connections between a workflow and the subflows it calls
wf_workflow_execution Current-state records for workflows that run on the Global scope
wf_workflow_binding History of workflow runs and the record that triggered each run

The wf_workflow_instance table matters when one flow hands work to another. Global workflows get their own current-state records in wf_workflow_execution.

Why the binding log outlives a deleted context

The wf_workflow_binding table keeps a history of each run and the record that triggered it, and that history stops the system from running the workflow again once the Workflow Context record has been deleted. That protection holds even after the Workflow Context record for the earlier run has been deleted. Anyone clearing out old context records should expect the binding log to keep its own history.

How checking out creates a new version

Editing a published workflow starts with a checkout. In the Workflow Editor, open the workflow, click the menu icon in the title bar, and choose Checkout. The system creates a new version and assigns it to you. Only one user can hold a checkout at a time. While the checkout is open, changes apply to the user who holds it, and other users keep running the published workflow.

A few conditions shape this. If you work in a different domain from the published workflow, the new version is created in your domain. A workflow that has contexts associated with it cannot be deleted.

Why unique names matter

Each workflow has a unique sys_id, so two workflows can share a display name without a database conflict. That is typical in a domain-separated environment, where companies cannot see each other’s workflows. Elsewhere, identical names can lead a designer to change the wrong workflow, so giving each workflow a unique name helps keep designers from editing the wrong one.

Validation before publishing

Validation looks for problems that could stop a workflow being published or cause it to fail. Its validators check for conditions such as multiple End activities, disconnected transitions, incorrect table references, missing subflows, and dependencies affected by update sets. Each result carries one of three levels. Info describes the version, for example by naming the lowest common table. Warning flags an anomaly that might compromise execution, such as a missing activity input transition. Info and Warning results can both be published. A Critical result, such as a missing or invalid subflow or a missing transition, prevents publishing and running in production.

The validation report header shows an overall score equal to the most severe level found, plus a count of checks at each level. The body lists Type, Level and Message for each check. To run validation, use the validate icon in the Workflow Editor title bar, or choose Validate Workflow from the title bar menu. Publishing validates the workflow automatically. Validation needs the snc_required_script_writer_permission role together with the workflow_publisher role, which carries validate rights.

The versions list rules for a runnable workflow

Open the Versions related list by entering wf_workflow.list in the navigation filter and opening a workflow. Three rules apply. There should be one workflow version in the Checked out state. If there is only one version and it is not checked out, it must be both Active and Published. If there are several versions, only one of them is Published.

A workflow runs when a checked-out version is available to the user who holds the checkout and a valid published version is available to users with permission to run it. A main flow containing a subflow that fails these conditions cannot execute against a current record transaction. To clear the block, remove the subflow from the main flow or change its published and active states.

Publishing and what running contexts see

Publish from All > Workflow > Workflow Editor by opening the workflow and choosing Publish in the title bar menu. Publishing makes the workflow available to all users. The role is snc_required_script_writer_permission plus one of workflow_admin or workflow_publisher. Validate first, so that missing subflows and disconnected transitions surface before publishing.

A newly published version does not change running contexts. Each running context keeps the version it started with, and the next run uses the new published version.

Reading a running workflow context

A running workflow is a Workflow Context. The record holds the state of the overall process, and related lists hold each activity’s state, the results of finished activities and the execution path. The context canvas draws executed paths in blue and non-executed paths in grey. Open a context from the Workflow Context link on the task form the workflow powers, or from Workflow > All Contexts. Show Timeline and Show Workflow display progress in two formats. Cancelling a context sets its State to Canceled, and the cancelContext(context) script can cancel a running context. An onCancel script can clean up unresolved activities.

Stage tables and default stages on a table

The wf_stage table holds the stage definitions used by workflows. A stage_set is a named set of stages that can populate several workflows, and stage_set_entry holds its members. The stage_set_table relates a stage set to a table, so the set supplies the default stages for new workflows on that table. This table replaces the wf_default_stage table. One stage can be shared across several activities. On the Requested Item table, a stage shows In progress while an activity that sets it is active.

Supporting history, definition and timing tables

The wf_history and wf_transition_history tables record executed activities and transitions, and wf_log holds the events of each workflow. The wf_executing table holds activities running in active contexts, and wf_command is temporary storage for workflows that are currently executing. Activity usage sits in wf_activity, while activity definitions sit in wf_activity_definition and wf_element_definition, with transitions in wf_transition and conditions in wf_condition. Timing data sits in wf_workflow_timing, wf_estimated_runtime_config and wf_workflow_schedule.

Pausing contexts with the pause utility

The Workflow Pause Utility pauses or resumes all contexts, a subset of them, or individual contexts, and can resume them at a set time. It runs from the plugin com.glideapp.workflow.pause, and requesting it requires the admin role. Once active, it writes to wf_pause_request (each pause request and its resume time), wf_pause_status (each paused context and its scheduled resume), wf_pause_group_request (group pauses) and wf_pause_snapshot (state before pausing and after resuming). A pause waits for the executing activity to finish before holding the context.

Subflows and passing variables

The Parallel Flow Launcher activity launches multiple subflows in parallel. To pass values into a subflow, define its inputs with Edit Inputs in the title bar menu. Each input is stored in the Variables table, var_dictionary. Add the subflow to the parent by dragging it from the Workflows tab, then map inputs in the New Activity dialog using static values or ${variable_name}. Subflows that run on Requested Item cannot receive variables. Each ending transition path in a subflow should include a Return Value activity.

Domain separation and the workflow tables

With domain separation enabled, workflows and their activities take on the domain of the user who creates or publishes them. The wf_workflow_version table has no domain field and inherits the domain of its parent wf_workflow record. A child-domain user can check out, but not copy, a parent-domain workflow. Checkout creates a unique wf_workflow record in the child domain, which overrides the parent version once it is published. A running workflow keeps its starting user’s domain and credentials until it waits, such as for an approval, and then continues in that domain under the approver’s credentials.

Frequently asked questions

Which table holds the workflow record itself?

The primary record of each workflow is stored in wf_workflow. Its published and checked-out editions are stored in wf_workflow_version, and each running instance is a wf_context record.

How does a checked-out version differ from a published one?

A checked-out version is held by one user, who makes changes in it. A published version is the copy that users with permission to run the workflow use. While a checkout is open, its changes apply to the user who holds it, and everyone else keeps running the published version.

Does publishing a new version change a run that is already happening?

No. A running context keeps the version that was available when it started. The next time the workflow runs, it uses the new published version.

Which roles are needed to publish a workflow?

Publishing requires the snc_required_script_writer_permission role together with one of workflow_admin or workflow_publisher.