Field Styles Not Working

Ali Usman
Tera Contributor

I Create a Style for my STATE field.

I am trying to change the color for a certain state value so As per this PD I created the following

  • Field: State
  • Value: javascript: current.u_state == "Draft"
  • Style: background-color:red; color:white;

(My State field is called u_state)

But it does not work, I also tried to change the value to the following (which is the value in u_state field for [Draft] state)

  1. javascript: current.u_state == "1"
  2. javascript: current.u_state == 1

It doe not work.

To see if the style actually works, if I leave the [Value] field empty my state field changes color but I want it to change color when the state is in Draft.

What am I doing wrong?

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

field styles with value will work only on list.

Are you sure you are comparing correct choice value for Draft

Field styles on list are evaluated only once and they show the style based on database value of that field

If you change the state value and save and then refresh the list it would show the newer style matching the respective condition

This should work fine provided Draft is having choice value as 1

javascript: current.u_state.toString() == '1'

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

field styles with value will work only on list.

Are you sure you are comparing correct choice value for Draft

Field styles on list are evaluated only once and they show the style based on database value of that field

If you change the state value and save and then refresh the list it would show the newer style matching the respective condition

This should work fine provided Draft is having choice value as 1

javascript: current.u_state.toString() == '1'

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Thanks @Ankur Babatunde  styles with the value only work in LIST (I missed that)