- 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-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.