Overview: Workflows in ApplicationsIssue Goals Understand how to specify the conditions under which a workflow will runUnderstand how to run a workflow from a Glide RecordLearn how to copy a Workflow 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 ClosedThe addition of Comments or Work NotesReassignment 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? Navigate to the Workflow Editor.If the Workflow Context pane is still open, close it.Select the Gear Menu > Publish icon.Your workflow should look like this: Gear Menu > Copy. Fill out the form as follows:Workflow Name: K14 Workflow Application Demo. Click OK.Notice the contents of the Activity Tree in the Workflow Editor. Gear Menu > Properties.Change the Table to Change Request [change_request]. Click Update.Your Activities Tree should include a new Category folder: 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 Select the main tab of your ServiceNow Instance. Change > Create New. Click the Submit button.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. 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.Select the Workflow Log Related List. 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? Return to the Workflow Editor. Add create task activity Find the Create Task Activity in the Tasks Category folder.Drag the Create Task Activity onto the canvas hovering between Log Trace Message and Run Script until the line turns blue. Name: Task Assigned from Workflow.Task Type: Change TaskPriority: 3 – ModerateFulfillment group: Database San DiegoAssigned to: Don GoodliffeShort Description: K14 Demo of a Change Task assigned from inside a workflow.Instructions: Thanks for joining us today. Enjoy your conference NOW! 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 Find the Log Trace Message Activity in the Tasks Category folder.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. Fill in the form as follows:Name: Log Trace After Task. Click the Submit button. Your workflow should look like this: Return to the main ServiceNow tab.Change > Create New.Click the Submit button. A new Change record is created. Note the Change record number.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. Select the K14 Workflow Application Demo that is Executing. 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. 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? Close the Workflow Context tab and return to the ServiceNow tab. The Workflow Context form should still be displaying.Using the form icon next to the ID, open the Change Request item. 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. In the Change Tasks list, open the CTASK record. Change the State to Closed Complete.Click the Update button.Workflow > All Contexts. Notice that the workflow is now finished. Select the Workflow Context for the finished Change Request.Select the Show Workflow Related Link. 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.