Skip to main content
Version: 4.7.0

Flow

Creates a Flow record (sys_hub_flow) that defines a series of actions to execute when triggered.

Signature

Flow(
config: FlowConfig,
trigger: Trigger,
callback: (params: FlowParams) => void
)

Parameters

PositionNameTypeDescription
1configFlowConfigFlow metadata and execution context
2triggerTriggerFlow activation point -- created via wfa.trigger()
3callback(params: FlowParams) => voidFlow body containing actions and flow logic

Import

import { Flow, wfa, trigger, action } from "@servicenow/sdk/automation";

TemplateValue, Time, and Duration are available globally from @servicenow/sdk/global -- do not import them.


Flow Configuration Properties

PropertyTypeRequiredDefaultDescription
$idstring / Now.ID[...]Yes-Unique identifier for the flow
namestringYes-Display name shown in the ServiceNow UI
descriptionstringNo-Flow purpose and behavior
runAs'system' | 'user'No'user'Execution security context
runWithRolesstring[]No[]Required role sys_ids granting temporary elevated permissions
flowPriority'LOW' | 'MEDIUM' | 'HIGH'No'MEDIUM'Execution queue priority
protection'read' | ''No''If 'read', the flow is read-only in the UI
flowVariablesRecord<string, Column>No{}Flow-scoped typed variables, used with wfa.flowLogic.setFlowVariables
stagesRecord<string, FlowStageConfig>No{}Named stage declarations for tracking flow execution progress. Each key must match the value field inside the corresponding FlowStage() call

Trigger Parameter

The second argument is a Trigger produced by wfa.trigger(). A flow must declare exactly one trigger.

wfa.trigger(
triggerType, // trigger.record.created, trigger.scheduled.daily, etc.
config: { $id: string, annotation?: string },
parameters: { /* trigger-type-specific */ }
)

For all trigger types, parameter tables, and outputs, see the Trigger API.


Body Callback

The third argument is a function that receives a params object and contains the flow body.

Signature

(params: FlowParams) => void

FlowParams Structure

The shape of params depends on the trigger type. Common members:

{
trigger: {
current: Record, // Current record (record triggers)
previous?: Record, // Previous state (record-update trigger)
run_start_date_time: DateTime,
// ... trigger-specific outputs (subject/body for inboundEmail, etc.)
},
stages: Record<string, FlowStageRef> // References to declared stages, used with wfa.stage()
}

Access dynamic data via wfa.dataPill(source, type) -- see the Flow Guide → Data Pills section.

Body Contents

The body may contain:

  • wfa.action(...) -- built-in (action.core.*) or custom action invocations -- see the Action API (built-ins) and Custom Action API
  • wfa.subflow(...) -- subflow invocations -- see the Subflow API
  • wfa.flowLogic.* -- conditional branching (if/elseIf/else), loops (forEach), loop control (exitLoop/skipIteration), flow control (endFlow) -- see the Flow Logic API
  • wfa.flowLogic.setFlowVariables(...) -- assigning flow-scoped variables

For when to pick which configuration values, end-to-end examples, anti-patterns, and best practices, see the Workflow Automation Flow Guide.