- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-09-2020 08:26 PM
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?
images/icons/flag_red.gif
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-09-2020 09:25 PM
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:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-11-2020 04:04 PM
Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-12-2020 10:13 AM
You are welcome

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-11-2021 09:59 AM
Hi Jim,
Is there a way to make that icon a clickable link?
Thanks,
Stacy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-11-2021 11:49 AM
Not with the "g_form.addDecoration()" method. But you could add the "field_decorations" attribute to the field and have a UI Macro appear to the right of the field.
There's no specific documentation on it, but you add "field_decorations=ui_macro_name" to the Dictionary record of the field and the macro would be rendered beside the field.
https://docs.servicenow.com/bundle/quebec-platform-administration/page/administer/reference-pages/co... and search for "field_decorations", but again not much.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-09-2020 09:27 PM
BTW, these posts might help with posting questions in the future: