Skip to Content
Knowledge is Power, so learn 🎉
Tutorial16 03 2025Unlock ServiceNow Superpowers: A Beginner's Guide to Building Your First Workflow

Unlock ServiceNow Superpowers: A Beginner’s Guide to Building Your First Workflow

ServiceNow is a powerhouse platform for streamlining IT and business processes. At its heart lies the workflow engine, a visual tool that allows you to automate tasks and create efficient, repeatable processes. This guide will walk you through the fundamentals of creating your first ServiceNow workflow, even if you’ve never touched it before. We’ll cover the basics, illustrate with practical examples, and provide step-by-step instructions to empower you to build your own automated solutions.

What is a ServiceNow Workflow?

Think of a workflow as a digital flowchart. It’s a sequence of activities that are triggered by a specific event and then automatically execute to achieve a desired outcome. Workflows can automate virtually anything, from approving requests to onboarding new employees to resolving incidents.

Key components of a workflow:

  • Trigger: The event that initiates the workflow (e.g., a new incident record being created).
  • Activities: The individual tasks or actions performed within the workflow (e.g., sending an email, updating a record, approving a request).
  • Transitions: The paths that connect activities, determining the flow based on conditions or outcomes (e.g., “if the request is over $1000, route it to the manager”).
  • Canvas: The visual workspace where you design and build your workflow.

Getting Started: Accessing the Workflow Editor

  1. Log in to your ServiceNow instance. You’ll need appropriate permissions to access the workflow editor (typically workflow_admin or workflow_creator roles).
  2. Navigate to Workflow > Workflow Editor. You can find this using the application navigator in the left sidebar.

Creating Your First Workflow: A Simple Incident Assignment

Let’s build a basic workflow that automatically assigns incidents to a specific assignment group based on the category selected.

1. Create a New Workflow:

  • In the Workflow Editor, click “New Workflow”.
  • Fill out the following fields:
    • Name: Assign Incident by Category
    • Table: Incident [incident]
    • If condition matches: Choose “record is inserted or updated”. We want the workflow to run when a new incident is created or updated.
    • Access: Change it to “All scopes”.
    • Description: A brief explanation of what the workflow does (e.g., “Assigns incidents to specific assignment groups based on category”).
  • Click “Submit”. This will open the workflow canvas.

2. Add the “Begin” and “End” Activities:

These are automatically created for you. They mark the start and end points of the workflow.

3. Add a “Run Script” Activity:

  • In the Workflow Editor’s left pane, search for “Run Script” under “Core Activities”.
  • Drag and drop the “Run Script” activity onto the workflow canvas between the “Begin” and “End” activities.
  • Connect the “Begin” activity to the “Run Script” activity by dragging the connector (the circle on the edge of the activity) from “Begin” to the “Run Script” activity.
  • Connect the “Run Script” activity to the “End” activity.

4. Configure the “Run Script” Activity:

  • Double-click the “Run Script” activity to open its properties.
  • Name: Assign Group based on Category (this is just a descriptive name for the activity).
  • Script: This is where you’ll write the JavaScript code to assign the incident. Replace the default script with the following:
(function executeProcess( /*GlideRecord*/ current, /*Workflow*/ workflow, /*WorkflowExecutionContext*/ workflowContext) { // Get the incident category. var category = current.category; // Define a mapping between categories and assignment groups. var assignmentGroupMap = { 'inquiry': 'Service Desk', // Replace 'Service Desk' with the sys_id of the Service Desk group 'software': 'Software Support', // Replace 'Software Support' with the sys_id of the Software Support group 'hardware': 'Hardware Support' // Replace 'Hardware Support' with the sys_id of the Hardware Support group }; // Look up the assignment group in the mapping. var assignmentGroupName = assignmentGroupMap[category]; // If an assignment group is found, assign the incident to it. if (assignmentGroupName) { // Query for the assignment group sys_id based on the group name. It's better to use sys_id directly, but this example uses name for simplicity. var gr = new GlideRecord('sys_user_group'); gr.addQuery('name', assignmentGroupName); gr.query(); if (gr.next()) { current.assignment_group = gr.sys_id; // Set the assignment group current.update(); // Important: Save the changes to the incident record! } else { gs.log("Assignment Group '" + assignmentGroupName + "' not found."); } } else { gs.log("No assignment group defined for category: " + category); } })(current, workflow, workflowContext);
  • Explanation of the Script:

    • The script retrieves the incident’s category using current.category.
    • It uses a JavaScript object (assignmentGroupMap) to store the mapping between incident categories and assignment group names. Important: You should replace the string values (‘Service Desk’, ‘Software Support’, ‘Hardware Support’) with the actual sys_id values of your assignment groups. You can find these sys_id values by going to User Administration > Groups in ServiceNow, opening the desired group, and looking at the URL.
    • It uses a GlideRecord query to get the group sys_id from the group name. It is best practice to use the sys_id directly to avoid issues with naming changes.
    • If a matching assignment group is found, it sets the assignment_group field of the incident record to the assignment group’s sys_id.
    • current.update() saves the changes to the incident record. This is crucial!
    • Error messages are logged using gs.log if an assignment group is not found. These logs can be viewed in the System Logs.
  • Click “Submit”.

5. Validate the Workflow:

  • Click the “Validate” button at the top of the Workflow Editor. This checks for any syntax errors or configuration issues.

6. Publish the Workflow:

  • Click the “Publish” button at the top of the Workflow Editor. This activates the workflow and makes it ready to run.

Testing Your Workflow

  1. Create a new incident record.
  2. Select a category that you defined in the assignmentGroupMap in your “Run Script” activity (e.g., “Inquiry”).
  3. Save the incident.
  4. Verify that the incident is automatically assigned to the correct assignment group. You should see the assignment group field updated automatically.
  5. Check the system logs (System Logs > System Log > All) for any error messages that might have been logged by your script.

Expanding Your Workflow

This is just a basic example. You can expand your workflow in many ways:

  • Add approvals: Use the “Approval - User” or “Approval - Group” activities to route requests for approval.
  • Send notifications: Use the “Send Notification” activity to send email or SMS notifications.
  • Create tasks: Use the “Create Task” activity to create new tasks for specific users or groups.
  • Use conditions: Use the “If” activity to create branching logic based on specific conditions.
  • Integrate with other systems: Use Scripted REST APIs or other integration methods to connect your workflow to external systems.
  • Timer activities: Use timer to add a delay in the process

Best Practices for Workflow Development

  • Keep it simple: Break down complex processes into smaller, more manageable workflows.
  • Use descriptive names: Give your workflows and activities meaningful names that clearly indicate their purpose.
  • Comment your code: Add comments to your script activities to explain what the code does.
  • Test thoroughly: Test your workflows in a development environment before deploying them to production.
  • Use version control: Track changes to your workflows using version control.
  • Leverage existing activities: Take advantage of the built-in activities provided by ServiceNow to avoid reinventing the wheel.
  • Use GlideRecord judiciously: Avoid querying inside loops wherever possible. Optimize your GlideRecord queries.

Conclusion

You’ve now built your first ServiceNow workflow! This is just the beginning of your journey. By understanding the fundamentals of workflow creation and exploring the available activities, you can unlock the true power of ServiceNow and automate countless processes, saving time, improving efficiency, and transforming the way your organization works. Keep experimenting, keep learning, and keep building!

Last updated on