Skip to content

Commit aa7d133

Browse files
authored
Display Info Message of Incident Count of Assigned-To user when Field Assigned-To changes (#2436)
* Create README.md * Add files via upload screenshot from pdis * Create clientScript.js * Create glideAjaxIncidentCount.js
1 parent 7dd74b5 commit aa7d133

File tree

5 files changed

+71
-0
lines changed

5 files changed

+71
-0
lines changed
79.2 KB
Loading
73.5 KB
Loading
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
## Display Info Message of Incident Count of Assigned-To User When Field Assigned-To Changes
2+
3+
Displays a message showing the count of **open incidents** assigned to a user whenever the **Assigned To** field changes on the Incident form.
4+
5+
- Helps assess the assignee’s **current workload** by fetching and displaying active incident counts (excluding *Resolved*, *Closed*, and *Canceled* states)
6+
- Shows an **info message** with the count of the assignee's assigned incidents
7+
- Uses an **onChange Client Script** on the **Assigned To** field and a **GlideAjax Script Include** called from the client script to fetch the count dynamically
8+
9+
---
10+
11+
### Info Message Example 1
12+
![Incident_Count_message_1](Incident_Count_message_1.png)
13+
14+
### Info Message Example 2
15+
![Incident_Count_message_2](Incident_Count_message_2.png)
16+
17+
---
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
2+
if (isLoading || newValue === '') return;
3+
4+
// Clear any previous messages
5+
g_form.clearMessages();
6+
7+
// Create GlideAjax object to call the Script Include
8+
var ga = new GlideAjax('IncidentAssignmentCheck');
9+
ga.addParam('sysparm_name', 'getIncidentCount');
10+
ga.addParam('sysparm_user', newValue);
11+
12+
13+
ga.getXMLAnswer(function(response) {
14+
var count = parseInt(response, 10);
15+
16+
17+
if (isNaN(count)) {
18+
g_form.addErrorMessage("Could not retrieve open incident count.");
19+
return;
20+
}
21+
22+
var userName = g_form.getDisplayValue('assigned_to');
23+
var msg = userName + " currently has " + count + " incidents assigned ";
24+
25+
if (count >= 5) {
26+
g_form.addInfoMessage(msg + " Please review workload before assigning more incidents");
27+
} else {
28+
g_form.addInfoMessage(msg);
29+
}
30+
});
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
var IncidentAssignmentCheck = Class.create();
2+
IncidentAssignmentCheck.prototype = Object.extendsObject(AbstractAjaxProcessor, {
3+
4+
getIncidentCount: function() {
5+
var user = this.getParameter('sysparm_user');
6+
var count = 0;
7+
8+
if (user) {
9+
var gr = new GlideAggregate('incident');
10+
gr.addQuery('assigned_to', user);
11+
gr.addQuery('state', 'NOT IN', '6,7,8');
12+
gr.addAggregate('COUNT');a
13+
gr.query();
14+
15+
if (gr.next()) {
16+
count = gr.getAggregate('COUNT');
17+
}
18+
}
19+
return count;
20+
},
21+
22+
type: 'IncidentAssignmentCheck'
23+
});

0 commit comments

Comments
 (0)