Skip to content
Tutorials Center
My learning

Topics

Lesson 37 of 39 ยท Projects and Practice

Project: Automate Incident Triage in ServiceNow

Design an incident triage automation end to end: data model, assignment rules, a before business rule, a Flow Designer flow, notifications and tests, with a JavaScript simulator.

In this project you design a complete automation for the service desk: when an incident arrives, it should be categorized, prioritized, assigned and announced without a human reading every ticket. You will use ideas from the whole course: tables, business rules, flows, notifications, SLAs and ACLs. Build it in your own developer instance, and use the simulator here to check your logic first.

The instance steps are described, not run. The simulator is JavaScript written for this lesson and models the rules so you can test them quickly. It is not ServiceNow code.

Requirements

  1. If the short description mentions certain keywords, set the category (network, hardware, software, access).
  2. Calculate priority from impact and urgency; an incident from a VIP caller gets urgency raised by one level.
  3. Assign it to the right group from the category.
  4. If priority is 1, notify the on-call manager immediately and add a work note.
  5. Anything not categorized goes to a triage queue for a human.
  6. Every decision is written as a work note so agents can see why.

Step 1: prepare the data

  • Create groups: Network, Service Desk, Desktop Support, Identity and Access, Triage.
  • Add a boolean field u_vip on the User table (or use the existing VIP field).
  • Create a System Property acme.triage.keywords or a custom table u_triage_rule (keyword, category, group, order) so admins can edit rules without code. Prefer a table: it is easier to maintain and test.

Step 2: the business rule

Use a before rule on Incident, operation Insert, condition Category is empty. Keep the logic in a Script Include so the rule stays short.

JavaScript
// Script Include: TriageEngine (server side, read-only here)
var TriageEngine = Class.create();
TriageEngine.prototype = {
  initialize: function () {},

  classify: function (text) {
    var gr = new GlideRecord('u_triage_rule');
    gr.orderBy('order');
    gr.query();
    var lower = (text || '').toLowerCase();
    while (gr.next()) {
      if (lower.indexOf(gr.getValue('keyword')) > -1) {
        return { category: gr.getValue('category'), group: gr.getValue('group'), keyword: gr.getValue('keyword') };
      }
    }
    return null;
  },

  type: 'TriageEngine'
};
JavaScript
// Business rule script (before insert)
(function executeRule(current, previous) {
  var result = new TriageEngine().classify(current.short_description);
  if (result) {
    current.category = result.category;
    current.assignment_group = result.group;
    current.work_notes = 'Triage: matched keyword "' + result.keyword + '"';
  } else {
    current.assignment_group.setDisplayValue('Triage');
    current.work_notes = 'Triage: no keyword matched, sent to the Triage queue';
  }
})(current, previous);

Because it is a before rule, setting fields on current needs no update().

Step 3: priority and the VIP rule

Let the platform's Priority Data Lookup compute priority from impact and urgency. For the VIP rule, add a second before rule (order 200, after the lookup rule) that lowers urgency by one when current.caller_id.vip == true. Remember that lower number means more urgent.

Step 4: the flow for critical incidents

In Flow Designer create a flow:

  • Trigger: Record Created on Incident, condition Priority is 1 - Critical, run Once.
  • Action: Look Up Record on sys_user_group for the on-call group, and read its Manager.
  • Action: Send Email to the manager with the number, short description and a link.
  • Action: Update Record on the incident: add a work note On-call manager notified.
  • Add an error handler that creates a task for the Service Desk if the email fails.

Step 5: SLA

Create a Priority 1 SLA definition (4 hours resolution, 24x7 schedule, start condition Priority is 1, pause when State is On Hold, stop when State is Resolved). Add a 75% escalation email.

Step 6: test plan

Write test cases before you build, then run them.

Case Input Expected
1 "VPN is down for everyone" network, Network group
2 "Laptop screen cracked" hardware, Desktop Support
3 "Strange noise from room 5" no match, Triage group
4 VIP caller, medium urgency urgency raised, priority recalculated
5 Priority 1 email sent, work note added

Simulate the rules

Run the simulator first. Add your own keywords and cases, and change the order of rules to see why order matters.

JS Simulator: triage rules for incoming incidents

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Extend it. What happens with a description that contains both "vpn" and "password"? Which rule wins, and is that what you want? Rule order decides, so document it.

JS Simulator: test the test plan automatically

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Hardening

  • Idempotence: the rule only fires when Category is empty, so edits do not retrigger it.
  • Security: the Script Include is server-only; the rules table needs a role such as triage_admin for writes.
  • Performance: the rules table is small, so the query is cheap; if it grows, cache it.
  • Observability: work notes explain each decision, and a report counts incidents sent to Triage so you can add missing keywords.
  • Move it: keep all changes in one update set named after the story and test it on a test instance before production.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why use a before business rule to set category and group on insert?

    A before rule runs prior to the database write, so changes to current are included in the save.
  2. 2. Why store keywords in a table instead of in the script?

    A rules table lets non-developers adjust triage logic safely and is easy to test.
  3. 3. In the simulator, which rule applies when a description matches two keywords?

    Rules are evaluated by order and the first match wins, so order must be documented.
  4. 4. What does the Once run option protect against in the P1 flow?

    Once runs the flow a single time per record instead of on each update.

Summary

  • The design combines a rules table, a Script Include, before rules, a flow for P1, an SLA and tests.
  • Work notes document each automated decision; rule order must be explicit.
  • Test cases come first; the simulator lets you check logic before building on an instance.
  • Package everything in one update set and test on a non-production instance.

Next: Project: A Catalog Item with Approval and Fulfillment