Skip to content

Commit 2eef425

Browse files
authored
Send notification if the incident remains unassigned for more than 5 days (#1514)
* script.js * readme.md * script.js * script.js
1 parent a3765d0 commit 2eef425

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
This is a UI Action script that adds a button to the Incident form. When clicked, it will check if the incident has been unassigned for more than 5 days.
2+
If this condition is met, the button will trigger a notification to the manager of the incident's assignment group, informing them that the incident is still unassigned.
3+
4+
Below are the conditions when UI action will be created:
5+
Table: Incident
6+
Show Insert: False
7+
Show Update: True
8+
Form Button: Checked (to add the button on the form)
9+
Condition: current.assigned_to.nil() && current.assignment_group
10+
11+
The code contains below vaidations:
12+
- The script checks if the incident has been unassigned for more than 5 days by comparing the current date with the sys_created_on date using gs.daysAgo().
13+
- It verifies that the incident has an assignment group. If it does not, it displays an error message.
14+
- Queries the sys_user_group table to get the assignment group’s manager. If a manager is found, it sets up a notification to send an email directly to the manager.
15+
- Provides feedback to the user if the notification was sent or if there were issues (like missing assignment group or manager).
16+
- Redirects the user back to the current incident form after the UI Action runs.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Check if the incident has been unassigned for more than 5 days
2+
var unassignedDuration = gs.daysAgo(current.sys_created_on);
3+
if (unassignedDuration < 5) {
4+
gs.addErrorMessage("The incident has been unassigned for less than 5 days.");
5+
action.setRedirectURL(current);
6+
return;
7+
}
8+
9+
// Check if the incident has an assignment group
10+
if (current.assignment_group.nil()) {
11+
gs.addErrorMessage("No assignment group is set for this incident.");
12+
action.setRedirectURL(current);
13+
return;
14+
}
15+
16+
// Get the assignment group's manager
17+
var assignmentGroup = new GlideRecord('sys_user_group');
18+
if (assignmentGroup.get(current.assignment_group)) {
19+
var manager = assignmentGroup.getValue('manager');
20+
21+
if (manager) {
22+
// Create a notification
23+
var notification = new GlideEmailOutbound();
24+
notification.setFrom('[email protected]');
25+
notification.setSubject("Alert! Incident " + current.number + " is still unassigned");
26+
notification.setBody("The incident " + current.number + " has been unassigned for more than 5 days. Please assign it promptly.");
27+
notification.setTo(manager);
28+
29+
// Send the email
30+
notification.send();
31+
32+
gs.addInfoMessage("Notification sent to the assignment group's manager.");
33+
} else {
34+
gs.addErrorMessage("The assignment group has no manager defined.");
35+
}
36+
} else {
37+
gs.addErrorMessage("Could not find the assignment group.");
38+
}
39+
40+
action.setRedirectURL(current);

0 commit comments

Comments
 (0)