Skip to content
Tutorials Center
My learning

Topics

Lesson 21 of 39 ยท Workflows and Flow Designer

Data Pills, Flow Variables and Logic in Flow Designer

Learn how ServiceNow data pills move values between flow steps, how flow variables and Look Up Records work, and how If, For Each and Parallel control the path.

A flow is only useful if its steps can share information. Step 1 finds a user, step 2 emails that user, step 3 writes a comment containing the email's subject. In Flow Designer this sharing happens through data pills. This lesson explains pills, flow variables, looking up records, and the three logic blocks you need most: If, For Each and Do The Following In Parallel.

Data pills

A data pill is a chip that represents a value produced earlier in the flow. When a step has an input field, you can type text or drag a pill into it. The pill picker groups values by where they come from:

  • Trigger: the record that started the flow (for example Trigger - Record Created > Incident Record > Short description).
  • Earlier steps: outputs of actions above (for example 1 - Look Up Record > Record > Caller).
  • Flow variables: values you stored yourself.
  • Flow Variables / Subflow inputs and Flow Constants where available.

Pills can be dot-walked. If the trigger record has a Caller reference, you can open it and choose Caller > Manager > Email. Dot-walking follows reference fields into the related record, just as in scripts.

You can mix pills with text. A comment input of Hello pill(Caller name), your incident pill(Number) is open yields a normal sentence at run time. If a pill's value is empty (an unfilled field), the sentence simply has an empty gap, so test with sparse records.

Rename every action. A pill labelled 3 - Look Up Record is hard to recognize in a long flow, whereas 3 - Find the on-call engineer is obvious.

Look Up Record and Look Up Records

Use Look Up Record when you expect at most one result, for example "the user with this email". The output is a single record pill. Use Look Up Records (plural) when you expect a list, for example "all open incidents assigned to this group". The output is a record list that you can loop over with For Each.

Both actions take a table, a condition and optionally an order and a limit. Always filter as narrowly as you can. A lookup with no condition on the Incident table would read every incident.

If a single lookup finds nothing, the output record pill is empty, and a later step that uses it can fail. After a lookup, add an If that checks Record is not empty.

Flow variables

A flow variable is a named value you create with the Set Flow Variables action. It has a type (String, Integer, True/False, Record, Reference, Array.Object and others). Typical uses:

  • Count how many records a loop handled.
  • Remember a decision made early so that later branches can use it.
  • Build a text message piece by piece.

Because Flow Designer has no general assignment operator, changing a number means a Set Flow Variables step (or the Data Utilities actions) such as "increment by one". Plan for that when you design a loop.

If, Else If and Else

The If block holds a condition, built with the same filter-style editor as triggers but comparing pills. Under it you add steps that run only when the condition is true. Else If and Else add alternatives. Nested If blocks are allowed, but deep nesting is hard to read: when you nest more than two levels, consider a subflow.

flowchart TD
    S["Look Up Records: open incidents of group"] --> L["For Each incident"]
    L --> C{"If age over 4 hours"}
    C -->|yes| N["Send reminder to group manager"]
    C -->|no| X["Do nothing"]
    N --> L
    X --> L
    L --> D["After loop: log the count"]

A lookup feeds a loop; each pass tests a condition and may send a reminder.

For Each

For Each takes a record list or an array and repeats the steps inside it once per item. Inside the loop, a new pill group appears for the current item. Things to know:

  • Steps inside a loop run once per item, so a loop over 5,000 records runs 5,000 times. Limit the lookup.
  • A loop runs the items one after another. Use it for work with dependencies between items.
  • Exit loop and Skip iteration let you stop early or move to the next item.
  • Data from inside the loop is usually not available after it, so store results in a flow variable first.

Do The Following In Parallel

This block runs several branches at the same time. It suits independent work, such as notifying a manager and creating a task for facilities. It does not suit work where a later branch needs an earlier branch's output. The flow continues after all branches finish.

Wait For Condition and Wait For a Duration

Wait For Condition pauses the flow until a record meets a condition, for example State is Resolved. Wait For a Duration pauses for a fixed time. Use waits sparingly: each waiting flow stays open and shows as In Progress in the executions list.

A stand-in for pills, lookups and loops

The code below is a JavaScript model of the same ideas. It is not ServiceNow code. Records are plain objects, a lookup is a filter, dot-walking is property access, and the loop updates a counter variable.

JS Stand-in: lookup, dot-walk, loop and flow variable

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Look at the dot-walk line: users[inc.caller].manager follows a reference to a user, then to that user's manager. If the manager were null, the line would throw an error, just as a real flow fails when a pill is empty. The next stand-in adds the guard that a good flow has.

JS Stand-in: guard against empty pills

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Common mistakes

  1. Using a pill before it exists. You can only use outputs from steps above the current one.
  2. Looping over an unfiltered lookup. Always filter and limit.
  3. Forgetting the empty case. Check for empty before dot-walking into a reference.
  4. Expecting variables to change automatically. Only Set Flow Variables (or a Data Utility) changes them.
  5. Parallel branches that depend on each other. Use sequence instead.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What is a data pill?

    Pills carry values such as trigger fields, earlier step outputs and flow variables into later inputs.
  2. 2. Which action returns a list you can loop over?

    The plural action returns a record list that For Each can iterate.
  3. 3. How do you change a flow variable's value in the middle of a flow?

    Flow variables only change through a Set Flow Variables step or a data utility action.
  4. 4. Which problem fits Do The Following In Parallel best?

    Parallel branches run together and cannot rely on each other's results.

Summary

  • Data pills carry values from the trigger, earlier steps and flow variables; you can dot-walk through references.
  • Look Up Record returns one record, Look Up Records returns a list; filter both narrowly.
  • Flow variables change only through Set Flow Variables; For Each runs once per item.
  • Check for empty values before using pills in later steps.

Next: Subflows, Custom Actions and Error Handling