How to set a particular color for field.

coolsaurabh
Tera Contributor

I want that when a particular form open , color of a particular field should be red.

Ex:- On incident form I add a field name as color, Now I want its default value should be red.

1 ACCEPTED SOLUTION

Hi Sourabh,



You can achieve this by defining a field style on the "Color" field. Here is how you do :


1. Right click on the color field


2. go to Configure Styles.


3. Click on "New"


4. Select table where the field belongs.


5. Select the "Color" field in the Field name drop dow box.


6. In the Style field write this line: background-color:Red;


7. Submit.


You are done.



Happy Working !



Thanks,


Arnab


View solution in original post

14 REPLIES 14

Harish KM
Kilo Patron
Kilo Patron

Harish KM
Kilo Patron
Kilo Patron

sorry I misunderstood your question.. to make a default value..right click --configure dictionary--default valuer: here give it as red


Regards
Harish

Bharath40
Giga Guru

Hi Sourabh,



I don't clearly understood your question but as Harish mentioned to change the color of field value(Jerrod Bennet)   go with wiki article


To populate default value configure dictionary or to change color field write a OnLoad client script as below. (Category -red) refer to screenshot attached.



function onLoad() {


  //Change the description label to 'My New Label' with bold red text


  changeFieldLabel('category', 'Category', 'red', 'bold','yellow');


}



function changeFieldLabel(field, label, color, weight,bgColor){


  try{


  var labelElement = $('label.' +   g_form.getControl(field).id);


  labelElement.select('label').each(function(elmt) {


  elmt.innerHTML = label + ':';


  });


  if(color)


  {


//Label Color


  labelElement.style.color = color;


//Label Background color


  labelElement.style.background = bgColor;


  }


  if(weight)


  labelElement.style.fontWeight = weight;


  }catch(e){}


}


Source : Modifying the Label of Form Fields With Client Scripts - ServiceNow Guru


Field color.PNG


I would suggest using the documented way.

https://docs.servicenow.com/bundle/newyork-application-development/page/script/useful-scripts/concept/c_ChangeFormColorOnStateChange.html

 

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; } }