Workflows

Workflows in ServiceNow are flowchart-driven automation tools with a drag-and-drop interface. Workflows can be used to automate multi-step processes using various tools, including approvals, child-task generation, notifications, logical loops and scripting, if/then control flow, timers, and they can even wait for and react to user activity.

Versions of each workflow are stored in the Workflow Versions [wf_workflow_version] table. When a task matches the criteria set up for a workflow, that workflow will execute against that task, and perform activities on it. This relationship between one workflow version and one task, is called a Context. Contexts are stored in the Workflow Context [wf_context] table.

This setup is necessary because you might have workflow version 1 as the Published workflow version one day, and any tasks on that day will be executed with that workflow. However, if you make drastic changes to the workflow and re-publish it (thus creating a new version of the same workflow), you wouldn't want to start each existing task over from scratch; so the existing tasks would continue to execute with a given version of a workflow - whichever one was published when the task was created.

The graphical workflow editor (Workflow | Workflow Editor from the Application Navigator) gives you a visual representation of the contents and flow of a given workflow, in the form of a flowchart. Boxes in the workflow are referred to as (and correspond to) activities performed by the workflow. Lines drawn between the various activities correspond to the flow of the task, and are referred to as transitions:

When one activity in a workflow is completed, the transition executes the next workflow activity in the flowchart. In most cases, this transition is serialized or linear; from one activity to the next. Perhaps looping back, but always executing one activity at a time:

However, an activity can also have multiple lines drawn from a single exit condition, pointing to multiple activities. If this is the case, these activities will execute simultaneously:

In a situation like this, it's possible to save a workflow where one of these branches doesn't have an exit condition (a transition to another activity), but it isn't recommended. Instead, ServiceNow provides a Join activity, which you can use to merge the pergent paths back into a single transition-flow:

Not too dissimilar from the Join activity, Workflows in ServiceNow also have a Branch activity. However, using this activity is exactly the same as drawing multiple transition lines from a single exit condition on an activity!

As you may have noticed, each activity has a yellow exit condition at the bottom of the activity box. So far, the activities we've discussed have all had only one exit condition: Always. Clicking on the small square to the right of this exit condition, and dragging a line to another activity, allows us to create a transition from the first activity, to the next. However, some activities can have multiple exit conditions. The Join activity is one such example, as it has two exit conditions: Complete and Incomplete.

If you draw a transition from two or more activities into the Join activity, the Join activity will wait for all of the activities that transition into it, to complete before transitioning to the next activity. However, in some cases, an alternative execution path might terminate on some activity that never redirects back to the Join activity. If this happens, then the Join activity's Incomplete exit condition will be what fires; otherwise, the Complete exit condition will fire. Thus, it is a good idea to draw a transition from the Incomplete exit condition in a Join activity, whenever it's possible for a preceding activity to follow a transition path that doesn't necessarily lead back to that Join activity; otherwise, it's possible for your workflow to become stuck!