Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Incident Count of Selected Configuration Item with Info Message and Link to its Related Incident

Displays a message showing the count of open incidents associated with a selected **Configuration Item (CI)** whenever the **Configuration Item** field changes on the Incident form.

- Helps quickly identify whether the selected CI has existing incident by fetching and displaying active incident counts (excluding *Resolved*, *Closed*, and *Canceled* states).
- Shows an **info message** with a **clickable link** that opens a filtered list of related incidents for that CI
- If more than five incidents are linked, a **warning message** appears suggesting Problem investigation for frequent or repeated CI issues.
- Uses an **onChange Client Script** on the *Configuration Item* field and a **GlideAjax Script Include** called from the client script to fetch the incident count

---

## Warning Message displayed on form when CI has 5 or more incidents

![CI_Incident_Message_Count_1](CI_Incident_Message_Count_1.png)

---

## Info Message displayed on form when CI has no incidents

![CI_Incident_Message_Count_2](CI_Incident_Message_Count_2.png)

---

## Info Message displayed on form when CI has incidents less than 5

![CI_Incident_Message_Count_3](CI_Incident_Message_Count_3.png)

---

## Upon clicking the url link filter list opens with incidents associated with CI

![CI_Incident_Message_Count_4](CI_Incident_Message_Count_4.png)

---
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') return;

g_form.clearMessages();

// Call Script Include to count incidents by CI
var ga = new GlideAjax('ConfigurationIncidentCheck');
ga.addParam('sysparm_name', 'getIncidentCount');
ga.addParam('sysparm_ci', newValue);

ga.getXMLAnswer(function(response) {
var count = parseInt(response, 10);
if (isNaN(count)) {
g_form.addErrorMessage("Could not retrieve incident count for this CI.");
return;
}

var ciName = g_form.getDisplayValue('cmdb_ci');
var url = '/incident_list.do?sysparm_query=cmdb_ci=' + newValue + '^stateNOT IN6,7,8';
var msg = 'Configuration Item <b>' + ciName + '</b> has <a target="_blank" href="' + url + '"><b>' + count + '</b> related incident(s)</a>.';

if (count === 0) {
g_form.addInfoMessage(
'Configuration Item <b>' + ciName + '</b> has no incidents associated with it.'
);
} else {
if (count >= 5) {
g_form.addWarningMessage(
msg + ' consider Problem investigation.'
);
} else {
g_form.addInfoMessage(msg);
}
}
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
var ConfigurationIncidentCheck = Class.create();
ConfigurationIncidentCheck.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getIncidentCount: function() {
var ci = this.getParameter('sysparm_ci');
if (!ci) return 0;

var gr = new GlideAggregate('incident');
gr.addQuery('cmdb_ci', ci);
gr.addQuery('state', 'NOT IN', '6,7,8');
gr.addAggregate('COUNT');
gr.query();

return gr.next() ? gr.getAggregate('COUNT') : 0;
},

type: 'ConfigurationIncidentCheck'
});
Loading