diff --git a/Server-Side Components/Business Rules/EnhanceIncidentWithProblem/EnhanceIncidentWithProblem.js b/Server-Side Components/Business Rules/EnhanceIncidentWithProblem/EnhanceIncidentWithProblem.js new file mode 100644 index 0000000000..db9bcfbb8b --- /dev/null +++ b/Server-Side Components/Business Rules/EnhanceIncidentWithProblem/EnhanceIncidentWithProblem.js @@ -0,0 +1,21 @@ +function executeRule(current, previous /*null when async*/) { + try { + // Check if problem_id was added or changed + var isNewLink = !previous || current.problem_id.changes(); + + if (isNewLink && current.problem_id) { + var problemGR = new GlideRecord("problem"); + + if (problemGR.get(current.problem_id)) { + var problemStatement = problemGR.short_description; + var problemNumber = problemGR.number; + + // Append to description + current.description = (current.description || '') + + "\n\n[Linked Problem] " + problemNumber + ": " + problemStatement; + } + } + } catch (ex) { + gs.error("An unexpected error occurred while enhancing the Incident with Problem details."); + } +})(current, previous); diff --git a/Server-Side Components/Business Rules/EnhanceIncidentWithProblem/README.md b/Server-Side Components/Business Rules/EnhanceIncidentWithProblem/README.md new file mode 100644 index 0000000000..9c0d01039d --- /dev/null +++ b/Server-Side Components/Business Rules/EnhanceIncidentWithProblem/README.md @@ -0,0 +1,17 @@ +# Enhance Incident Description with Linked Problem Statement + +## Overview +This ServiceNow Business Rule enhances Incident records by automatically appending the short description of a linked Problem record. It improves visibility and context for support teams working on related incidents. + +## Features +- Triggered when a Problem ID is newly linked or changed on an Incident. +- Fetches the Problem's short description and number. +- Appends the Problem Statement to both the Incident's short description and description fields. +- Includes general error handling to ensure stability. + +## Business Rule Configuration +- Table: `incident` +- When to Run: `before insert` and `before update` +- Condition: + ```javascript + current.problem_id.changes() || !previous