Notifications

2773 views

Overview: Workflow Contexts 

 

Goals
  • Running a Workflow.
  • Visualizing the Workflow Context.
  • Debugging simple workflows.

 

ServiceNow workflow context

A Workflow Context is a workflow that is executing in the Workflow Engine.

A workflow can be started in one of four ways:

  • From within the Workflow Canvas using the Green Arrow.
  • As part of a Glide transaction.
  • As a subflow called from inside a main flow.
  • From within a script using the Workflow Script Include.

A record in the Workflow Context maintains the state of the overall process. The Related Lists maintains the state of the Activities throughout the life cycle of the running workflow.

Once started, a Workflow Context will “run to wait.” That is, the Workflow Engine examines all the Activities currently executing. If an Activity is finished, the Workflow Engine evaluates an Activity’s conditions. For all true conditions, the engine looks to the end of the transition arrow for what to do next. If an activity is not finished, it is assumed to be waiting for an outside Event (Approval, Task Complete, Probe Complete etc.). 

  

NOTE: If there are any Workflow Editor tabs open at this time, close them now.

  1. Workflow > Workflow Editor.
  2. In the Workflow Editor, Gear Menu > New.


     
  3. Fill out the form as shown:

    Name: K14 Context Demo
    Table: Global [global]
     
  4. Click Submit.



    The Workflow Version has a model that at this time contains Begin and End Activities. This is a complete workflow and enough to create a context. In the header of the Workflow Canvas find the green arrow icon. This is the play button. When a workflow designer selects the play button the Workflow Version in the editor will execute.
     
  5. Select the Green play button.




     
  6. Click Submit to execute the K14 Context Demo workflow.



    This is the Context View. When a workflow has run or is running, the state of the workflow can be visualized in the Context View.

    The Workflow Editor uses colors to communicate different states of a workflow and its Activities. In the upper right hand corner of the Context View, find the blue question mark icon.

  7. Hover over blue question mark icon.



    Each color in the key indicates the state of an Activity executing in the workflow. In the key, blue indicates Finished. Looking at the activities on the Context Canvas, we can see that both Activities, Begin and End, are finished.



    The coloring of activities in the Workflow Context reflects the state of each individual Activity. The header of the Workflow Context canvas reflects the state of the overall workflow.



    The Canvas View of the Workflow Context is a convenient summary view. There is also a way to see the details of the Workflow Context.

     
  8. Workflow > All Contexts.



    The list shows all Workflow Contexts that have finished or are currently executing.
     
  9. Select K14 Context Demo Workflow Context from the list.

    NOTE: Switch to the tab view for easier navigation.



    To correlate the execution of the Workflow Context to the artifacts of the Workflow Context see the diagrams. 

 

Establish the workflow context
 

 

Looking at the values in the Workflow Context form, we can see that even without doing any work, a Workflow Context has significant status to report.

  • The Workflow Version that ran this Workflow Context.
  • The Result (if any) of the Workflow.
  • The ID of the document that associated with the Workflow Context.

When a Workflow runs from the green play button of the Workflow Context the ID will always be Workflow Execution: << the name of the version running >>. When a Workflow is run against a Glide Record, this ID is the document id. For example, a Routine Change workflow will run against a Change Request Workflow. The ID of that Workflow Context will be Change Request: CHG0030002.


Run transitions

 


State of the context


The final state of a Workflow is one of the following values:

  • Finished
  • Cancelled
  • Executing 
  1. Scroll to the bottom of the Workflow Context form.
  2. Select the Workflow Executing Activities Related List.



    Because the workflow is already finished, there are no entries into this system.
     
  3. Select the Workflow Activity History Related List.



    The Workflow Activity History reflects the start, state and end time of all the activities that executed in this Workflow Context.
     
  4. To the left of the list select the Personalize List icon.


     
  5. Select the Activity index property in Available and move it to Selected using the Add arrow.
  6. Click OK.

    Your Activity History list should look like this:



    The Activity index is a number assigned to an activity when it is created. This value is the only reliable method of knowing the exact execution order of the Activities. The timestamps assigned to the Activities are precise to a second. Several activities can execute within a second, making Started ordering an inconsistent means of determining precise order of execution.

    On the diagram, activities will appear to be executing concurrently based on how they are drawn and how the context colorizes their state. However, the order of appearance of transitions at the same transition level on the diagram does not necessarily reflect the order of execution. The Activity index will definitely provide the precise order of execution. In debugging large workflows or workflows that have multiple transitions from a single condition, this value is enormously helpful.
     
  7. Click the Workflow Transition History tab.



    The Workflow that we ran had one very simple transition in it, Begin -> End. All transitions that execute are written to this list.
     
  8. Select the Workflow Log list.

    Your Workflow Log list should look like this:



    In a subsequent lab we will address the details of workflow logging. For now, take note of where the Workflow Log list is, and what entries are written to the Log by default.
     
  9. Select the Workflow Queued Commands list.

    Your Workflow Queued Commands list should look like this:



    The entries in the Workflow Queued Commands list are transient, and should not be there by the time a workflow is finished.  

 

Outside events


Recall that part of the stimulus in the process of Running Transitions in a workflow is receiving outside events. 

 

If an Outside Event comes into the Workflow Engine while the Engine is currently running active transitions in its ‘run to rest’ process, the Outside Event will be temporarily cached in the Workflow Queued Commands table. When the ‘run to rest’ process completes it’s active transitions, it will retrieve incoming events from this the Workflow Queued Commands list. The commands are deleted as they are read from the table. 


Summary


Workflow in ServiceNow names a running workflow a Workflow Context.

The Workflow Context maintains the state of the overall process in the Workflow Context record.

The Workflow Context maintains the state of the individual activities as they execute in a series of related lists. These lists maintain the state of currently executing activities, the result of finished activities, and the execution path the workflow took through the process model.

The Workflow Context canvas provides a visual representation of the execution path the workflow took through the process model. The state of each activity (finished, executing, cancelled, error) is represented using the color palette. The executed paths are represented in the color blue; the non-executed paths are represented in grey.  

Article Information

Last Updated:2015-05-02 12:07:15
Published:2014-05-16