Skip to content

Commit 632d717

Browse files
authored
Create clientScriptCiIncident.js
1 parent 7276109 commit 632d717

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
2+
if (isLoading || newValue === '') return;
3+
4+
g_form.clearMessages();
5+
6+
// Call Script Include to count incidents by CI
7+
var ga = new GlideAjax('ConfigurationIncidentCheck');
8+
ga.addParam('sysparm_name', 'getIncidentCount');
9+
ga.addParam('sysparm_ci', newValue);
10+
11+
ga.getXMLAnswer(function(response) {
12+
var count = parseInt(response, 10);
13+
if (isNaN(count)) {
14+
g_form.addErrorMessage("Could not retrieve incident count for this CI.");
15+
return;
16+
}
17+
18+
var ciName = g_form.getDisplayValue('cmdb_ci');
19+
var url = '/incident_list.do?sysparm_query=cmdb_ci=' + newValue + '^stateNOT IN6,7,8';
20+
var msg = 'Configuration Item <b>' + ciName + '</b> has <a target="_blank" href="' + url + '"><b>' + count + '</b> related incident(s)</a>.';
21+
22+
if (count === 0) {
23+
g_form.addInfoMessage(
24+
'Configuration Item <b>' + ciName + '</b> has no incidents associated with it.'
25+
);
26+
} else {
27+
if (count >= 5) {
28+
g_form.addWarningMessage(
29+
msg + ' consider Problem investigation.'
30+
);
31+
} else {
32+
g_form.addInfoMessage(msg);
33+
}
34+
}
35+
});
36+
}

0 commit comments

Comments
 (0)