ServiceNow Workflow Wizardry: Automate Your Way to Efficiency with This Step-by-Step Tutorial
ServiceNow is a powerful platform for automating business processes, and at its heart lies the Workflow Editor. Whether you’re managing IT incidents, onboarding new employees, or handling customer service requests, workflows can drastically improve efficiency and reduce manual effort. This tutorial will guide you through the basics of ServiceNow workflows, providing you with practical examples to get you started.
What is a ServiceNow Workflow?
Think of a workflow as a digital representation of a business process. It’s a series of steps or activities that need to be performed in a specific order to achieve a particular goal. These activities can range from sending email notifications to updating records in the database.
Why Use Workflows?
- Automation: Automate repetitive tasks, freeing up your team to focus on more strategic initiatives.
- Standardization: Ensure consistency in how processes are executed across the organization.
- Efficiency: Reduce manual errors and speed up process completion times.
- Visibility: Track the progress of processes and identify bottlenecks.
- Reporting: Gain insights into process performance and identify areas for improvement.
Getting Started: Accessing the Workflow Editor
- Log in to your ServiceNow instance. (Typically
https://your-instance-name.service-now.com
) - Navigate to the Workflow Editor: Type “Workflow Editor” in the application navigator (left-hand sidebar) and click on it. You may need to have the
workflow_admin
role or a similar role with Workflow administration rights.
A Step-by-Step Guide to Creating Your First Workflow
Let’s create a simple workflow that sends an email notification when a new incident is created.
1. Create a New Workflow:
- In the Workflow Editor, click the “New Workflow” button.
- Fill in the following fields:
- Name: “New Incident Notification” (or something descriptive)
- Table:
Incident
(This specifies that the workflow will be triggered by events related to the Incident table) - If condition matches: Select this checkbox. This allows you to trigger based on conditions.
- Condition:
Active is true
(This workflow will only run on active incidents. This is just for demonstrative purposes and might not be practical in production) - Description: Briefly describe the purpose of the workflow.
- Click “Submit”. This opens the graphical workflow editor.
2. Understanding the Workflow Editor Interface:
The Workflow Editor consists of several key components:
- Canvas: The main area where you build your workflow.
- Palette: Contains a list of available workflow activities (e.g., “Send Notification”, “Create Task”, “Run Script”).
- Properties Pane: Allows you to configure the settings for each activity you add to the canvas.
3. Adding and Configuring Activities:
- Add a Begin Activity: A “Begin” activity is automatically placed on the canvas when a new workflow is created. This signifies the start of the workflow.
- Add a Send Notification Activity:
- From the Palette, find the “Send Notification” activity. You can either drag it onto the canvas or double-click it.
- Position the “Send Notification” activity to the right of the “Begin” activity.
- Connect the Activities: Click on the output port (the small circle) of the “Begin” activity and drag a line to the input port of the “Send Notification” activity. This defines the flow of execution.
- Configure the Send Notification Activity:
- Click on the “Send Notification” activity to select it.
- The Properties Pane will display the activity’s settings. Configure the following:
- Name: “Incident Created Notification”
- Type: “Email” (should be the default)
- To:
${caller_id}
(This uses a dot-walk to get the email of the caller associated with the incident.) Alternatively, you could usegs.getUserID()
to send to the logged in user creating the record for testing. - Subject: “New Incident Created: ${number}” (This includes the incident number in the subject)
- Message HTML: You can craft a rich HTML email. For example:
<p>A new incident has been created:</p>
<p>Number: ${number}</p>
<p>Short Description: ${short_description}</p>
<p>Description: ${description}</p>
<p>Priority: ${priority}</p>
<p>Please review and take appropriate action.</p>
<p><a href="${URI_BASE}${sys_id}">View Incident</a></p>
- Add an End Activity: Drag an “End” activity from the palette to the canvas.
- Connect the Activities: Connect the output port of the “Send Notification” activity to the input port of the “End” activity.
4. Validating and Publishing the Workflow:
- Validate: Click the “Validate” button at the top of the Workflow Editor to check for errors. Address any errors before proceeding.
- Publish: Click the “Publish” button at the top of the Workflow Editor to make the workflow active and available for use.
Testing Your Workflow
- Create a New Incident: Navigate to “Incident” > “Create New” in the application navigator.
- Fill in the Required Fields: Populate the necessary fields, like “Caller”, “Short Description”, and “Description.”
- Save the Incident: Click “Submit”.
- Check Your Email: Verify that you received the email notification generated by the workflow. Check your spam folder if you don’t see it.
Advanced Workflow Concepts
- Activities: ServiceNow offers a wide range of activities beyond “Send Notification.” Explore activities like:
- Approval Activities: Request approvals from specific users or groups.
- Task Activities: Create tasks for users to perform.
- Run Script Activities: Execute custom JavaScript code.
- Timer Activities: Introduce delays in the workflow execution.
- Utility Activities: Activities related to logging and record manipulation
- Conditions: Use conditions to control the flow of the workflow based on specific criteria. You can use “If” activities and JavaScript to define complex conditions.
- Transitions: Transitions (the lines connecting activities) can also have conditions associated with them. This allows for branching workflows based on specific values.
- Context Variables: Context variables are used to pass data between activities within a workflow. They are often accessed using the
${variable_name}
syntax. Theworkflow.scratchpad
object is useful for storing variables. - Subflows: Subflows are reusable workflows that can be called from other workflows. This promotes modularity and reduces redundancy.
- Workflow Properties: Each workflow has properties that you can set, such as the table it applies to, the conditions under which it runs, and the users who are allowed to execute it.
Example: Approving Incidents with Workflow
This example demonstrates how to add an approval process to the incident workflow.
- Modify the Existing Workflow: Open the “New Incident Notification” workflow in the Workflow Editor.
- Add an Approval - User Activity: Drag an “Approval - User” activity from the palette and place it between the “Begin” and “Send Notification” activities.
- Connect the Activities: Connect the “Begin” activity to the “Approval - User” activity, and the “Approval - User” activity to the “Send Notification” activity.
- Configure the Approval - User Activity:
- Name: “Incident Approval”
- Users: Choose a user or group to approve the incident. You can use a script to dynamically determine the approver based on incident data.
- Add an “If” Activity Drag an “If” activity from the palette and place it between “Approval - User” and “Send Notification”. Connect “Approval - User” to “If”.
- Configure “If” Activity:
- Condition:
workflow.scratchpad.approvalState == 'approved'
(assuming that you setworkflow.scratchpad.approvalState
in the “Approval - User” activity based on the approval status). Alternatively, use theanswer = (current.approval == 'approved');
approach.
- Condition:
- Create a “Create Task” activity Drag a “Create Task” activity from the palette and place it after the “If” activity on the “false” path.
- Connect the Activities: Connect “If” to “Create Task” and then to the “End” activity. From the “If” activity’s “true” path, connect it to the “Send Notification” activity.
- Configure Approval User activity Script
// Inside the Approval - User activity's Script field (Advanced view)
workflow.scratchpad.approvalState = 'pending';
current.work_notes = "Approval requested from " + approvers.toString();
var approvers = [];
var gr = new GlideRecord('sys_user');
gr.get('6816f79cc0a8016401c5a33be04be441'); //Replace this with a proper user or group lookup, such as manager of the affected user.
approvers.push(gr.sys_id.toString());
approval_target.setValue('approvers', approvers); //Sets the list of approvers for this record.
action.setRedirectURL(current);
action.setReturnURL(current);
This simplified example demonstrates the power of workflows to automate complex processes. In a real-world scenario, you would likely add more error handling, reporting, and customization.
Best Practices for Workflow Design
- Plan Your Workflow: Before you start building, clearly define the process you want to automate.
- Keep it Simple: Avoid overly complex workflows that are difficult to maintain. Break down large processes into smaller, more manageable subflows.
- Use Descriptive Names: Use clear and descriptive names for your workflows and activities.
- Document Your Workflows: Add comments and descriptions to explain the purpose of each activity.
- Test Thoroughly: Test your workflows in a non-production environment before deploying them to production.
- Use Logging: Include logging activities in your workflows to track their execution and troubleshoot issues.
Conclusion
ServiceNow workflows are a powerful tool for automating business processes and improving efficiency. By understanding the basics of the Workflow Editor and exploring the various activities available, you can create sophisticated workflows that streamline your operations. This tutorial provided a step-by-step guide to creating your first workflow and introduced some advanced concepts. Remember to plan your workflows carefully, keep them simple, and test them thoroughly to ensure they meet your needs.