- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-07-2023 12:22 AM
Hi all,
I have a requirement to change the color of the cmdb_ci field in the change form to red when the criticality of the ci is business critical and amber when it is mission critical, basically we need to query the ci record to get the criticality, i have tried the following script but it is not working, please assist.
client script:
function onLoad() {
var ciSysId = g_form.getValue('cmdb_ci');
if (ciSysId) {
var ga = new GlideAjax('getChangeDetails');
ga.addParam('sysparm_name', 'getCICriticality');
ga.addParam('sysparm_ci', ciSysId);
ga.getXML(function(response) {
var answer = response.responseXML.documentElement.getAttribute('answer');
var clr = $('sys_display.' + g_form.getControl('cmdb_ci').id);
if (answer) {
// Set background color based on criticality value
if (answer === 'Business Critical') {
clr.style.backgroundColor = 'red';
} else if (answer === 'Mission Critical') {
clr.style.backgroundColor = 'amber';
} else {
// Reset background color if it's not business or mission critical
clr.style.backgroundColor = '';
}
}
}
}
});
}
getCICriticality: function(ciSysId) {
var crit = '';
if (ciSysId) {
var cmdbci = new GlideRecord('cmdb_ci');
cmdbci.addQuery('sys_id', ciSysId);
cmdbci.query();
if (cmdbci.next()) {
crit = cmdbci.getValue('u_component_criticality');
}
}
return crit;
},
Thank you.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-08-2023 07:16 AM - edited ‎11-08-2023 07:17 AM
I have updated the client script as below and it is working as expected.
var clr = g_form.getControl('sys_display.change_request.cmdb_ci');
if (answer) {
// Set background color based on criticality value
if (answer == 'Business critical') {
clr.style.background = '#FF0000';
//alert("Setting background to red");
} else if (answer == 'Mission Critical') {
clr.style.background = '#FFBF00'; // amber code
//alert("Setting background to amber");
} else {
// Reset background color if it's not business or mission critical
clr.style.background = '';
}
Thanks.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-07-2023 12:27 AM
@Frankline J Update your script include as follows and check if the fix works.
getCICriticality: function() {
var crit = '';
var ciSysId = this.getParameter("sysparm_ci");
if (ciSysId) {
var cmdbci = new GlideRecord('cmdb_ci');
cmdbci.addQuery('sys_id', ciSysId);
cmdbci.query();
if (cmdbci.next()) {
crit = cmdbci.getValue('u_component_criticality');
}
}
return crit;
},
Make sure that your script include is client callable.
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-07-2023 12:34 AM
Hi Sandeep, Thanks for you response, I have updated the script include but still the background is not getting changed.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-07-2023 03:10 AM
@Frankline J Did you use the alert
var answer = response.responseXML.documentElement.getAttribute('answer');
alert(answer);
To check if you are receiving the correct response from the server. Also, on your client script, make sure the Isolate Script checkbox is unchecked.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-07-2023 03:32 AM - edited ‎11-07-2023 03:33 AM
Hi there,
Did you try it by using field styles? If not please go to System UI > Field Styles. Select you table and field name and in value you need to either evaluate your script include or you can directly compare any field value by (current.field_name == '').
Once above is done you need to select the color of the field in Style field eg: (background-color: #D3D3D3;).
Save the record and check. I'm sure this will work for you.
If my solution works please mark my answer Correct.
Thanks,
Utpal