colour coding for a field based on SLA breaching timing

konijetisumanth
Giga Guru

Hi Community 

 

I have a requirement to populate the SLA Original breach time but it should also follow the color code to the field. populating the data have been configured , but need help in how to make an automated way to make the filed color changes as per the SLA breach timing.

 

could you please help me how can i configure color coding  to Fileds.

2 REPLIES 2

Mark Manders
Mega Patron

You can use field styles for this: https://docs.servicenow.com/bundle/washingtondc-platform-administration/page/administer/navigation-a...

 


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

sravya chipilla
Tera Contributor

Write an onchange client script

(function executeRule(current, gForm, gSNC) {
var breachTime = current.getValue('u_original_breach_time'); 
var now = new Date();
var breachDate = new Date(breachTime);

if (breachTime) {
var diff = (breachDate - now) / (1000 * 60 * 60); 

if (diff < 0) {
gForm.setStyle('u_original_breach_time', 'color', 'red'); 
} else if (diff <= 2) {
gForm.setStyle('u_original_breach_time', 'color', 'orange'); 
} else {
gForm.setStyle('u_original_breach_time', 'color', 'green'); 
}
}
})(current, gForm, gSNC);

write the field values as per your form.