Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Adding field icon in script

MStritt
Tera Guru

I'm using the following code in a UI Policy to add a gold background color to my Contact field on my case form, when a certain value (TRUE) is set on a field in the Contact table. This is working successfully. However, I'd like to add an icon instead of a background color. How would I change ctrl.style.backgroundColor = 'gold'; to use an icon instead?

find_real_file.png

images/icons/flag_red.gif

1 ACCEPTED SOLUTION

Jim Coyne
Kilo Patron

I would use the built-in "addDecoration" function.  Here's an example from an onChange Client Script we use:

//remove any existing decoration
g_form.removeDecoration("status", "icon-stop-watch", "Status", "color-orange");
g_form.removeDecoration("status", "icon-error-circle", "Status", "color-red");
g_form.removeDecoration("status", "icon-success-circle", "Status", "color-green");


var color = "";
var icon = "";
switch (newValue) {
  case "80":
  case "100":
    color = "color-orange";
    icon = "icon-stop-watch";
    break;
  case "200":
  case "300":
    color = "color-red";
    icon = "icon-error-circle";
    break;
  case "1000":
    color = "color-green";
    icon = "icon-success-circle";
}
if (color) {
  g_form.addDecoration("status", icon, "Status", color);
}

 

We show a different icon/color combination based on the value of a field.

This is how it ends up looking:

find_real_file.png

 

View solution in original post

15 REPLIES 15

Dhananjay Pawar
Kilo Sage

Hi,

Try this line instead.

$j("<img src='images/icons/flag_red.gif'>").insertBefore("span[id='case.contact']");

 

Thanks,

Dhananjay.

Hi Dhananjay,

Thanks for the quick reply. Unfortunately, that didn't work.

 

Hi,

Can you paste your script here.

Thanks,

Dhananjay.

find_real_file.png

Here's the 'When to Apply' tab.

find_real_file.png

When configured for background color, it works. Just want to use an icon instead of a color.