How to colour a field red?

peterraeves
Mega Guru

When a field is mandatory but not filled in, the label blinks for 2 seconds and the field becomes red. I want to replicate this behaviour. I found that g_form.flash does the former, now how would I be able to do the latter?

6 REPLIES 6

Prasun
Giga Guru

Check this blog. I think what you are looking for will suffice this.



Custom Field Styles — ServiceNow Elite


I wonder, how much people on this forum actually read the question. I have seen so many people reply half heartedly, just wasting people's time instead of helping...



Prasun, did you actually read my question and that article? My question asks how to change the colour of the field similar to how it changes when a mandatory field is not filled in, while your article explains how to change the colour of the field label...


So you want to change a field's color based on some condition?



Check this one. If priority is changing, then the field color will change for the priority field.



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


  var elementID = gel("incident.priority");


  switch (newValue) {


    case "1":


  elementID.style.backgroundColor = "red";


    break;


    case "2":


  elementID.style.backgroundColor = "tomato";


    break;


    case "3":


  elementID.style.backgroundColor = "orange";


    break;


    case "4":


  elementID.style.backgroundColor = "yellow";


    break;


    case "5":


  elementID.style.backgroundColor = "green";


    break;


    default:


  elementID.style.backgroundColor = "white";


    break;


  }


}


That did not do it either.



I figured it out myself after all. By using gel("incident.category").style.borderColor = 'red'; I could get it to look red, but it stays red, even after filling in a value. So unless servicenow has a function ready for this behaviour, I will just leave it blank. Having to meddle with the html and write client scripts just to get the border to show red, would not be very clean. So I guess I'll have to settle with only the label flashing. Unless someone could point me in the direction of a SN function, if that would exist.