If flow logic
Summarize
Summary of If flow logic
The If flow logic feature in ServiceNow allows you to selectively execute one or more actions within a flow only when specified conditions are met. These conditions are based on the current record’s data, such as task state or urgency. Actions or subflows can be placed inside the If flow logic block, and they run only if the conditions evaluate to true.
Show less
You can also nest If flow logic blocks by adding child blocks within the Then branch of a parent If flow logic block, enabling more complex conditional flows.
Key Features
- Condition-based execution: Define conditions that determine when the actions inside the Then branch run.
- Data pill scope: Data pill values set inside a Then branch are only available within that branch. Referencing them outside results in null values.
- Condition labeling: You can assign descriptive labels to condition branches to improve readability, especially for complex conditions.
- No outputs: If flow logic itself does not produce outputs; it controls the execution flow.
- Nested If blocks: Child If flow logic blocks can be nested inside parent blocks to handle multi-level conditions.
Best Practices and Guidelines
- Avoid referencing data pill values outside their branch: Values set inside a Then branch are local to that branch only.
- Group similar conditions: Group matching condition types (e.g., all OR conditions or all AND conditions) into separate condition sets to prevent unexpected evaluation results.
- Use decision tables instead of multiple If blocks: To reduce duplication and improve maintainability, replace multiple If flow logic blocks that differ only by conditions with a single Make a decision flow logic block using a decision table.
Practical Example
For instance, to perform an action only when an incident has high urgency, you create an If flow logic block with a condition checking the urgency field. The flow executes the specified actions only if the urgency is high.
For more complex scenarios, like assigning an assignment group based on incident category, instead of multiple If blocks, use a Make a decision flow logic block with a decision table to map categories to assignment groups efficiently.
Execution and Monitoring
The flow execution details show the state, start time, and runtime of the If flow logic block. Configuration details include variable types, configurations, and runtime values, helping you verify whether branch conditions were met during execution.
Related Concepts
If flow logic works alongside other flow logic types such as Assign subflow outputs, Call a workflow, Do the following until, For Each, Make a decision, and others, providing a versatile toolkit for building complex, condition-driven workflows.
Selectively apply one or more actions only when a list of conditions is met.
Nested If flow logic blocks
You can add a child If flow logic block to a parent If flow logic block. Add the child If flow logic block to the Then branch of the parent flow logic block.
Inputs
| Input | Description |
|---|---|
| Condition label | Descriptive label for the conditions of branch. A label can be easier to read than a long or complex condition data pill value. |
| Condition | Conditions under which the branch runs. The flow only runs the contents of the Then branch when the conditions evaluate to true. |
Outputs
This flow logic has no outputs.
Perform an action on if an incident has a high urgency
In this example, the action is triggered when the incident record has a high urgency value.
Execution details
- The header shows the state, start time, and runtime for the flow logic.
- The Configuration Details section shows the details about the variables that are used by the flow, including the type, configuration, and runtime values for each variable. Use the condition variable to see if the branch conditions were met.
General guidelines
Use these general guidelines to create effective If flow logic blocks.
- Avoid referring to data pill values outside of the Then branch
- When you set a data pill value from inside a Then branch of If flow logic, the data pill value is only available to other actions in the same branch. Referencing a data pill value that was set inside a Then branch from outside of the flow logic branch produces a null value.
- Group matching condition types in their own condition sets
- Mixing conditions of different types for the same field values can produce unexpected results. For example, adding an AND condition to a group of multiple OR conditions for an incident short description can produce a
situation where the If condition never evaluates to true. Use condition groups to group similar condition types for the same field. For example, group all OR conditions for an incident short description in one condition
set and group all AND conditions for an incident short description in another condition set.
Figure 2. Example of grouping matching conditions into condition sets - Replace multiple If flow logic blocks with a Make a decision flow logic block
- Rather than create duplicate If flow logic blocks that only vary by their conditions, use a decision table to generate an answer. For example, suppose you want to use the incident category to set the assignment group of
an incident task record. Rather than create a duplicate If flow logic block for each category value, use the Make a decision flow logic to provide an answer for the assignment group.
Here is an example flow that uses three If flow logic blocks that each create an incident task record. The only difference between the If flow logic blocks are the conditions of the incident category.
Figure 3. Example of multiple If flow logic blocks that do the same action Here is an example flow that uses a single Make a decision flow logic block to determine the incident task assignment group from the incident category. The Create task action uses the output of the decision as an input.
Figure 4. Example of replacing multiple If flow logic blocks with a decision Here is an example decision table that uses incident record values as an input. The Conditions column consists of two incident category values. The results column consists of the assignment group to use for each condition value.
Figure 5. Example decision table Get Assignment Group from Category