- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-14-2024 10:31 AM
Hello everyone,
I'm working on a configuration in ServiceNow to dynamically change the color of a field based on the percentage value (u_sla) in the incident table. My goal is to make it so that:
- When u_sla is between 0% and 50%, the field is green.
- When u_sla is between 51% and 99%, the field is orange.
- When u_sla is 100% and above, the field is red.
Additional Details:
- The u_sla field is of type string and is currently read-only.
- The u_sla field retrieves its information from the task_sla table.
What I’ve Tried So Far
Field Styles and Script Include:
I created a Script Include called ColorCheck to return the appropriate color based on the u_sla value.
In each Field Style, I called the function ColorCheck().getColor() to check the value and apply the corresponding style.
Here’s the script I used in my Script Include:
var ColorCheck = Class.create();
ColorCheck.prototype = {
initialize: function() {},getColor: function(value) {
var slaValue = parseFloat(value);
if (isNaN(slaValue)) return '';if (slaValue >= 0 && slaValue <= 50) {
return 'green';
} else if (slaValue > 50 && slaValue < 100) {
return 'orange';
} else if (slaValue >= 100) {
return 'red';
}
return '';
},type: 'ColorCheck'
};For each Field Style (green, orange, red), I used a condition in the Value field as follows:
Green (0% to 50%):
javascript: new ColorCheck().getColor(current.u_sla) == 'green';Orange (51% to 99%):
javascript: new ColorCheck().getColor(current.u_sla) == 'orange';Red (100% and above):
javascript: new ColorCheck().getColor(current.u_sla) == 'red';
Despite this configuration, the u_sla field does not change color
Could anyone help me identify what might be missing or configured differently to achieve the dynamic color change?
Would there be a better approach to meet this requirement?
Thanks in advance for any help or suggestions!
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-18-2024 05:38 AM
My SLA field was a string, because I was trying to make it just like you said in your original post.
If the colors are appearing in the list view, that means the script must be returning the correct value, so it should be working in the form view. The field does have to be read only for it to show, but you said yours is read only, correct? If you try this in your PDI, does it work? If so, there might be some competing code in your instance. Maybe another field style or business rule?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-14-2024 10:52 AM
What are you using for the Style field in your field style record? I have some with conditions that are using something like this and they work:
background-color: tomato
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-14-2024 01:07 PM
Thank you for your response, I don't think that's the source of the problem.I also tried with Tomato.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-15-2024 04:54 AM
Can you include a screen shot of your Field Style?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-15-2024 10:05 AM
yes