Notifications

2643 views

Overview: Workflows in Applications 

 

Goals
  • Understand how to specify the conditions under which a workflow will run
  • Understand how to run a workflow from a Glide Record
  • Learn how to copy a Workflow.Enter 

 

Workflows and ServiceNow applications
The Workflow Engine is part of the Glide Script Engine. Because of this, a workflow can be configured to run as part of a Glide transaction.  Glide transactions in the ServiceNow Platform are associated with database tables. The Workflow Engine evaluates workflows that are associated with the table of a Glide transaction. If a Glide Record meets the conditions of a workflow and the user has the correct permissions, the workflow will run. 

The Workflow Engine on the insert of a Glide Record typically evaluates workflows and if conditions are met, a Workflow Context is created. The workflow will “run to rest” or “run to finish”.  If the workflow does rest, it is waiting for an event to come, typically from the Glide Record. The most common event on a Glide Record is an update from the form.

Here are some event examples:

  • A change of state from In Progress to Close
  • The addition of Comments or Work Notes
  • Reassignment of a user

Once the event is fired, the Workflow Engine evaluates the currently waiting Activities to see if the incoming update event is one that is relevant to the work of the Activity.

QUESTION: Where is the atomic work of a Workflow Activity in a Workflow defined?
  1. Navigate to the Workflow Editor.
  2. If the Workflow Context pane is still open, close it.
  3. Select the Gear Menu > Publish icon.

    Your workflow should look like this:


     
  4. Gear Menu > Copy.


     
  5. Fill out the form as follows:

    Workflow Name: K14 Workflow Application Demo.
     
  6. Click OK.



    Notice the contents of the Activity Tree in the Workflow Editor.



     
  7. Gear Menu > Properties.

    Change the Table to Change Request [change_request].
     
  8. Click Update.

    Your Activities Tree should include a new Category folder:


     
  9. Expand the Tasks Category folder.

     

    The Workflow Activities that are in the Task Category folder require at the minimum the Task table to complete their work.

    QUESTION: What are two ways to make the Workflow K14 Application Demo run right now? 

   

Create change record to create workflow context

  1. Select the main tab of your ServiceNow Instance.  
  2. Change > Create New.


     
  3. Click the Submit button.
  4. Workflow > All Contexts.



    Notice that, with the workflow being associated with a Glide Record, that ID of the workflow now reflects the Change Request association in the context list.
     
  5. In the Started column, select the context’s date and timestamp value of our test workflow.

    NOTE: In ServiceNow, to select a record in a list, always click on the value in the first column.



    The workflow association with the Glide Record also is shown in the ID of the workflow. You can see this association in the form.

  6. Select the Workflow Log Related List.


     
  7. Right click on an ACTIVITY source and select Show Matching.



    The output from the Log Trace Message activity identifies the table the Glide Record is associated with.

    QUESTION:  How do you control the Workflow Log output? 

  8. Return to the Workflow Editor.

Add create task activity
  1. Find the Create Task Activity in the Tasks Category folder.
  2. Drag the Create Task Activity onto the canvas hovering between Log Trace Message and Run Script until the line turns blue. 
  3. Name: Task Assigned from Workflow.

    Task Type: Change Task
    Priority: 3 – Moderate
    Fulfillment group: Database San Diego
    Assigned to: Don Goodliffe
    Short Description: K14 Demo of a Change Task assigned from inside a workflow.
    Instructions: Thanks for joining us today. Enjoy your conference NOW!


     
  4. Click the Submit button.

    QUESTION: The Workflow Engine will “run to rest” which means it will follow the transitions until it either ends or until a Workflow Activity causes it to wait. So far, all our demonstration workflows have run until they were finished. Looking at this Workflow Activity, will the Workflow “run to rest”?  



    NOTE: You may need to adjust the layout of your Workflow Activities.
     


Add log trace activity


  1. Find the Log Trace Message Activity in the Tasks Category folder.
  2. Drag the Log Trace Message Activity onto the canvas hovering between Create Task and Run Script until the line turns blue.

    NOTE: You may need to adjust the layout of your Workflow Activities.
     
  3. Fill in the form as follows:

    Name: Log Trace After Task.
     
  4. Click the Submit button. 

    Your workflow should look like this:


     
  5. Return to the main ServiceNow tab.
  6. Change > Create New.
  7. Click the Submit button. A new Change record is created. Note the Change record number.
  8. Workflow > Active Contexts.



    Notice the State column of the new record is Executing. This is a Workflow that has “run to rest”. Running workflows that are waiting for an event to nudge them on to be in a state of Executing.
     
  9. Select the K14 Workflow Application Demo that is Executing.


     
  10. Select the Workflow Executing Activities Referenced List. 

    Notice that there is an activity with the state of Running in the list. Activities with this state are waiting for an event to nudge them to transition to the next Activity.
     
  11. In the Related Links, select the Show Workflow.

    The Workflow Context Window will open in a separate tab.



    QUESTION: What are two Workflow Activity States that are represented by the colors on the in the workflow context?
     
  12. Close the Workflow Context tab and return to the ServiceNow tab. The Workflow Context form should still be displaying.
  13. Using the form icon next to the ID, open the Change Request item.


     
  14. Scroll to the Related Lists and select Change Tasks.



    Notice the values that are on the task. Look familiar? The task that is in this list is the task that was inserted by the Create Task of the workflow. Recall that check box on the Create Task Workflow Activity? 



    The completion of this task is what the workflow is waiting for.
     
  15. In the Change Tasks list, open the CTASK record.


     
  16. Change the State to Closed Complete.
  17. Click the Update button.
  18. Workflow > All Contexts.


     
    Notice that the workflow is now finished.
     
  19. Select the Workflow Context for the finished Change Request.
  20. Select the Show Workflow Related Link.


     
  21. Hover your mouse over the Create Task. 



    Notice that the same status that was available in the Activity History records is also available on the screen with the hover behavior. 


Summary


The Workflow Engine is part of the Glide Engine. Because of that, workflows will be invoked on the insert, update, delete or cancel database event. The Workflow Engine examines the table associated with the record and seeks all workflows that are associated with that table. The Workflow Engine will create a context for each workflow that is configured to execute for the given Glide Record.

The Workflow Engine can automate Task creation and wait for the task to be complete before continuing on.

If there is a Glide Record associated with a Workflow Context, the ID of the document is visible in the Workflow Context and is included in some Workflow Log messages.

Article Information

Last Updated:2016-05-11 08:50:46
Published:2014-05-16