OBLYTECH Logo
OBLYTECH Logo
ServiceNow Subflow Explained
Home / Guides, Services and Solutions / Concepts Explained / ServiceNow Subflow Explained

ServiceNow Subflow Explained

Definition and Purpose

A subflow is a reusable block of automation logic that can be called from other flows within ServiceNow. Think of it as a function or subroutine in programming: you build the logic once and invoke it from multiple places, reducing duplication and maintenance burden. Subflows run within the Flow Designer automation platform and support the same activities—API calls, variable assignments, conditionals, loops, and queries—as standalone flows. They accept input parameters and can return output values to calling flows.

Where Subflows Live in the Platform

Subflows are built and stored in the Flow Designer section of ServiceNow, accessible through the Flows and Subflows navigation menu. They appear in a dedicated list where you can search by name, edit, test, and manage versions. When you author a regular flow or another subflow, you add an Execute Subflow action to call it. You select the subflow by name, map input variables from your current flow to the subflow’s input parameters, and capture output values that the subflow returns. The subflow executes synchronously by default, meaning the calling flow waits for it to complete before proceeding to the next step.

Worked Example with Multiple Reuses

Suppose your organization sends notifications across multiple processes—incident assignment, change approval, request fulfillment, and knowledge article submission. Rather than building email logic into each flow, create a subflow called Send Business Notification that accepts input parameters like recipient email, subject line, message body, and priority level. The subflow contains all email activity, error handling, and logging. Now every flow that needs to send a notification calls Send Business Notification with the appropriate inputs, and all four flows share the same notification logic and behavior.

When you later need to update notification behavior—adding CC recipients, modifying templates, or implementing retry logic—you edit the subflow once, and all calling flows automatically use the new logic on their next execution. This eliminates redundancy and ensures consistency. Without subflows, you would maintain four separate copies of the same logic, and any change would require editing all four places, increasing risk of inconsistency or missed updates.

Common Misunderstandings and Clarifications

One confusion is between subflows and workflow processes. Workflow is an older ServiceNow automation engine; Flow Designer is the newer, recommended approach for automation. Subflows are Flow Designer constructs and do not work within the older Workflow system. If you need to call shared logic from workflows, you would use script includes instead.

Another misunderstanding is that subflows are asynchronous by default; they are actually synchronous unless explicitly configured otherwise, meaning the calling flow pauses until the subflow completes. Asynchronous execution requires specific configuration through scheduled flow execution or message queue mechanisms if you need non-blocking behavior. A third confusion is that subflows must be simple or short; they can actually contain complex multi-step logic, branching, error handling, nested conditionals, and even call other subflows. The only practical limits are overall complexity and execution time; subflows that run for many minutes may hit platform timeouts.

Related Concepts and Distinctions

Flow Designer is the broader automation engine; subflows are one component within it. Business rules and script includes are older ServiceNow customization mechanisms that predate flows and serve similar code-reuse purposes. Integration hub orchestrations are heavier-duty automation for complex multi-system workflows that may span minutes or longer. Scheduled flows run at specified intervals or after events; subflows are called synchronously from other flows. Understanding the distinctions helps you choose the right automation approach for each use case.

Best Practices for Designing Subflows

Build subflows for logic that is used in more than one place. If a task is unique to a single flow, embed it directly rather than creating a subflow; unnecessary abstraction adds complexity. Document your subflows with clear input and output parameter names so other developers understand how to call them. Version your subflows and test them independently before calling from multiple places. Consider error handling within the subflow to gracefully manage failures without crashing the calling flow. Avoid deep nesting of subflows calling other subflows, as this reduces readability and complicates debugging when failures occur.

When a Subflow Pays Off and When It Adds Friction

The reader here is a flow author who already reuses logic in more than one place and has started to feel the cost. A subflow earns its keep when the same sequence of actions must behave identically in several callers and when the owner of that behavior is not the owner of every caller. A notification template, a standard approval chain and a data enrichment step are typical examples. A subflow is a poor choice when the callers need different error handling, when the logic changes with every caller, or when a single author maintains everything anyway. In those cases a copy inside each flow is easier to reason about, even though it is duplicated.

Before choosing, compare the design against the integration pattern the subflow will serve. The useful distinction is between shared behavior and shared ownership. Two flows that call the same subflow share its behavior, but a change to the subflow reaches both on their next run. Before you publish a change, list the callers. If a caller is owned by a team that has not been told, the change is a release decision, not a developer tidy-up.

Situation Use a subflow Keep logic inline
Same steps in several flows owned by one team Often, if the steps are stable Acceptable while the team is small
Callers owned by different teams Yes, with a documented contract Only if each team needs its own variant
Caller needs its own error branch Return a status value and let the caller decide Usually preferred
Logic changes with every caller No Yes

Designing the Input and Output Contract

Many subflow problems start at the boundary. A subflow that accepts a loosely typed text value and passes it straight to a query will work until a caller sends an empty string, a value with a trailing space, or a reference that no longer exists. Treat each input as a contract. Define which inputs are required, what a valid value looks like, and what the subflow returns when validation fails. A status output with a short, fixed set of values is more useful to callers than an error message, because it can drive a branch without parsing text.

  1. Write down every caller and the input values it sends today.
  2. Mark which inputs are required and reject the call early when one is missing.
  3. Define one status output with a fixed list of values, and document what each value means.
  4. Return identifiers, not whole records, unless the caller needs the full record for its next step.
  5. Add a test call for each status value before the subflow is used by a second caller.

Where Subflows Go Wrong in Operation

Subflows that wrap an external system are often part of a wider IntegrationHub and API automation design. A subflow that performs an outbound call has to deal with the same failures as any integration, and a retry policy needs to be decided on purpose rather than left to chance. Timeouts, rejected credentials and rate limits all surface inside the subflow, and the caller sees only what the subflow returns. If the subflow swallows an error and returns success, the caller carries on with incomplete data and the problem appears much later, in a report or a customer conversation. Log the failure with enough detail to reproduce it, and return a status that tells the caller a retry is worth attempting or that a person must intervene.

Another common problem is hidden time. A subflow adds its own duration to every caller, so a short approval step that calls a slow enrichment subflow can make a user-facing action feel stalled. Measure the subflow on its own, and ask whether the caller really needs the result before it continues. When it does not, the work belongs in an asynchronous path, not inside the synchronous chain.

Checking That a Subflow Is Behaving

A working subflow shows three things in the execution history: each caller reaches the expected status, failures leave a reason that a support person can read, and the time taken stays steady across normal load. If any of these is missing, look at the subflow’s execution records before changing its logic. Many apparent subflow faults are caused by a caller passing a value the author never expected, which is visible in the input recorded for the failing run.

What to do when a change breaks a caller

Roll the subflow back to the previous published version if the flow tooling allows it, then reproduce the failing call with the exact input the caller sent. Only then edit the subflow. Editing under pressure, with a broken caller still live, is a common reason a small fix becomes an incident.

Decisions to Make Before You Build the Subflow

Settle four questions with the people who own the callers. Who approves a change to the shared logic. What is the agreed status vocabulary. Which team responds when the subflow fails. And how long a failed run should be kept for investigation. Writing these down takes less time than one unclear change, and it makes the subflow usable by someone who did not build it. Teams that already run flow governance will find a flow governance review a natural place to record these answers.

Questions People Ask About Subflows

Can a subflow call a script include directly?

Yes, and that can be the cleanest way to share code that the flow tooling does not express well; a script include is a common choice. Keep the script include small and named for the business action it performs, so the subflow reads as a sequence of business steps rather than a wrapper around a script.

Is there a limit to how deep subflows can nest?

Nesting is possible, but each level makes execution history harder to read and failures harder to trace. A practical rule is to keep nesting shallow enough that a support person can follow one failed run from the top-level flow to the failing action without opening more than a few records.

Should a subflow be versioned like application code?

Treat it that way for anything shared. Record what changed, who approved it and which callers were tested. Subflows that change silently are the ones that break callers nobody remembered existed.

Why would a team stop using a subflow it already built?

Usually because the subflow grew to serve two callers with conflicting needs and now carries flags that change its behavior. Splitting it into two focused subflows, or returning to inline logic for one caller, is a legitimate outcome of a review.

If you are deciding how shared automation should be governed across several teams, a structured review can settle the ownership question faster than a design debate.

Frequently asked questions

Can a subflow call another subflow?

Yes. Subflows can call other subflows, allowing you to build layers of abstraction and organize complex automation hierarchically. This is useful for grouping related activities, but avoid excessive nesting as it reduces readability and can complicate debugging.

What happens if a subflow fails or encounters an error?

By default, if a subflow encounters an error, it stops execution and the error propagates to the calling flow, halting it too. You can configure error handling within the subflow to catch specific failures and continue, or in the calling flow to handle subflow failures gracefully.

How do I pass variables and data to a subflow?

Subflows have defined input and output parameters. When you call a subflow using Execute Subflow action, you map values from your flow to those input parameters. The subflow can return output values that your flow captures and uses in subsequent steps.

Talk to Oblytech

Planning, running or fixing a ServiceNow programme? Tell us where you are and we will suggest a sensible next step.

Contact us