-
Notifications
You must be signed in to change notification settings - Fork 917
Enforce SLA Rules on Change Requests with Scheduled Job Trigger #1949
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| If a Change Request hasn't been moved to "Assess" state within 48 hours of submission, | ||
| automatically send a reminder and log escalation task. | ||
| This is a hybrid of a Business Rule + Scheduled Job (or Flow). | ||
| This code sets up an automated escalation process for change requests in ServiceNow. When a new change request is created, it schedules a job to run after 48 hours using a `sys_trigger`. | ||
| If the change is still in the "New" state at that time, the Script Include sends a notification event and creates an escalation task assigned to the Change Management group. This ensures timely review and prevents unattended change requests. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| var ChangeEscalationHelper = Class.create(); | ||
| ChangeEscalationHelper.prototype = { | ||
| initialize: function() {}, | ||
|
|
||
| checkAndEscalate: function(changeId) { | ||
| var gr = new GlideRecord('change_request'); | ||
| if (gr.get(changeId) && gr.state == '1') { // Assuming '1' = New | ||
| // Notify change manager | ||
| gs.eventQueue('change.escalate', gr, gs.getUserID(), ''); | ||
|
|
||
| // Log an escalation task | ||
| var task = new GlideRecord('task'); | ||
| task.initialize(); | ||
| task.short_description = "Escalation: Change not assessed in 48 hours"; | ||
| task.parent = gr.sys_id; | ||
| task.assignment_group.setDisplayValue('Change Management'); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This group is not the same for every company/instance. Can you add a comments so people know to adjust this? |
||
| task.insert(); | ||
| } | ||
| }, | ||
|
|
||
| type: 'ChangeEscalationHelper' | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| (function executeRule(current, gsn, gs) { | ||
|
|
||
| var timer = new GlideRecord('sys_trigger'); | ||
| timer.initialize(); | ||
| timer.name = "Change Escalation for: " + current.number; | ||
| timer.script = "new global.ChangeEscalationHelper().checkAndEscalate('" + current.sys_id + "');"; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would not pass the sysId like that ('" + current.sys_id + "'). Better to get the sysId and pass it like this: current.getUniqueValue(); |
||
|
|
||
| var triggerTime = new GlideDateTime(); | ||
| triggerTime.addSeconds(60 * 60 * 48); // 48 hours | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you think of a way this will be more configurable? For example using a system property where users can set the nr of hours? And in the script convert the hours entered to seconds? |
||
| timer.next_action = triggerTime; | ||
| timer.insert(); | ||
|
|
||
| })(current, gsn, gs); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you want to do this with code? Notifications can commonly be handled in the Flow. There is for example already an example SLA flow with reminders. If you can add to the readme why that would be helpful. Alternatively, include in the readme that there is also a Flow way of doing this, so people know that is also an option