Skip to content

Commit 8f53b8d

Browse files
Auto assign incident (#1102)
* Create Send Notification on New Incident Creation.js * Rename Send Notification on New Incident Creation.js to Send Notification on New Incident Creation * Rename Business Rules/Send Notification on New Incident Creation to Business Rules/Notification/Send Notification on New Incident Creation.js * Create readme.md * Create readme.md * Create Auto Assign Incident.js
1 parent bb7374e commit 8f53b8d

File tree

4 files changed

+33
-0
lines changed

4 files changed

+33
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Business Rule: Auto Assign Incident
2+
// When: Before Insert & Table: Incident
3+
(function executeRule(current, previous /*null when async*/) {
4+
if (current.assigned_to.nil()) {
5+
var group = new GlideRecord('sys_user_group');
6+
group.addQuery('name', 'IT Support');
7+
group.query();
8+
if (group.next()) {
9+
current.assigned_to = group.getValue('manager');
10+
}
11+
}
12+
})(current, previous);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This Business Rule runs before an incident is inserted.
2+
If no user is assigned, it looks up the "IT Support" group and assigns the incident to the group's manager.
3+
This ensures that incidents are promptly directed to the appropriate personnel.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Business Rule: Send Notification on New Incident Creation
2+
// When: After Insert and Table: Incident
3+
(function executeRule(current, previous /*null when async*/) {
4+
// Only send notification for newly created incidents
5+
if (current.isNewRecord()) {
6+
var gr = new GlideRecord('sys_user');
7+
gr.get(current.assigned_to);
8+
// Prepare the notification message
9+
var message = 'A new incident has been assigned to you: ' + current.number;
10+
// Send the notification
11+
gs.eventQueue('incident.new', current, gr.sys_id, message);
12+
}
13+
})(current, previous);

Business Rules/Notification/readme.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Trigger: This business rule runs after a new incident is inserted into the Incident table.
2+
Check: It checks if the record is new using current.isNewRecord().
3+
User Lookup: It retrieves the assigned user’s record using GlideRecord.
4+
Message Preparation: It constructs a message indicating a new incident has been assigned.
5+
Event Queue: Finally, it uses gs.eventQueue to send the notification event.

0 commit comments

Comments
 (0)