Client Script - Highlight Config Item

MrMK
Tera Contributor

Hi All.

 

I am trying to highlight the configuration item within the INC form utilising the VIP code from OOTB adjusted to  what I need but to no avail. I need this very simple, if CI is configured as Tier 1 then highlight it in red when selected in INC form.

 

I was able to have the "Style" working in the list using the below, which works fine.

 

javascript: current.cmdb_ci.u_service_tier == 'Tier 1'

 

For the Client Script in the INC table I am using the below, there are no errors but it just won't highlight the CI that has a Tier 1 selected in Service Tier dropdown.

 

Thanks in advance!

********************************************************

 

function onChange(control, oldValue, newValue, isLoading) {

var ciLabel = $('label.incident.cmdb_ci');

var ciField = $('sys_display.incident.cmdb_ci');

if (!ciLabel || !ciField) {

return;

}

 

if (!newValue) {

ciLabel.setStyle({backgroundImage: ""});

ciField.setStyle({color: ""});

return;

}

g_form.getReference('cmdb_ci', CITier1Callback);

}

 

function CITier1Callback(cmdb_ci) {

var ciLabel = $('label.incident.cmdb_ci');

var ciField = $('sys_display.incident.cmdb_ci');

if (!ciLabel || !ciField) {

return;

}

//check for Tier 1 status

if (cmdb_ci.u_service_tier == 'Tier 1'){

 

ciField.setStyle({color: "red"});

 

}else{

ciLabel.setStyle({backgroundImage: ""});

ciField.setStyle({color: ""});

}

}

1 ACCEPTED SOLUTION

For this version of the script to work you would need to have a field on the incident table and form named cmdb_ci_appl that is a reference to the cmdb_ci_appl table.

View solution in original post

5 REPLIES 5

Brad Bowman
Kilo Patron
Kilo Patron

Since this script uses DOM ($ shortcut) ensure the isolate script box is unchecked.

BradBowman_0-1665490119907.png

Also, ensure that 'Tier 1' is the exact value stored in your u_service_tier field on the CI table (case and space sensitive).

Hi.

 

Yes that has been ticked off, and all spaces there. I am thinking that there is an error somewhere as if I add "red" to the bottom 2

 

}else{

ciLabel.setStyle({backgroundImage: ""});

ciField.setStyle({color: ""});

}

}

 

Then it will auto apply red to all, so its almost like not reading the service tier field.

Trying adding an alert like this to see what it thinks the tier value is

alert('service_tier=' + cmdb_ci.u_service_tier);

and is service_tier a field you added to the cmdb_ci table, or one of the extended tables?

Thanks - you sent me on the right path, to say our CMDB is a bit of unmanaged mess. When I added the Tier field into a Configuration Item form then this now works as intended. I have previously added the Service Tier field to cmdb_ci_appl table, amended the script but it will not work, not sure where I might be going wrong, amended code below:
Thanks.

function onChange(control, oldValue, newValue, isLoading) {

  var ciLabel = $('label.incident.cmdb_ci_appl');

  var ciField = $('sys_display.incident.cmdb_ci_appl');

  if (!ciLabel || !ciField) {

  return;

  }

 

  if (!newValue) {

  ciLabel.setStyle({backgroundImage: ""});

  ciField.setStyle({color: ""});

  return;

  }

  g_form.getReference('cmdb_ci_appl', CITier1Callback);

}

 

function CITier1Callback(cmdb_ci_appl) {

  var ciLabel = $('label.incident.cmdb_ci_appl');

  var ciField = $('sys_display.incident.cmdb_ci_appl');

  if (!ciLabel || !ciField) {

  return;

}

  //check for Tier 1 status

  if (cmdb_ci_appl.u_service_tier == 'Tier 1'){

 

  ciField.setStyle({color: "red"});

 

      }else{

  ciLabel.setStyle({backgroundImage: ""});

  ciField.setStyle({color: ""});

}

}