- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-31-2017 10:00 PM
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.
Solved! Go to Solution.
- Labels:
-
Personal Developer Instance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-31-2017 11:33 PM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-31-2017 10:04 PM
section 2 here http://wiki.servicenow.com/index.php?title=Defining_Field_Styles#gsc.tab=0
Harish

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-31-2017 10:15 PM
sorry I misunderstood your question.. to make a default value..right click --configure dictionary--default valuer: here give it as red
Harish

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-31-2017 10:25 PM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-23-2019 10:15 AM
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; } }