How can I set the incident number text color to red when it is a P1 incident?

jesusnava
Giga Expert

Hello everyone, 

I would like to change the number of the text color to red when it is a P1 incident, I have this script but seems not to be working:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if (priority == '1') {
NumberField.setStyle({color: "red"});
}
//Type appropriate comment here, and begin script below

}

..........................................

Anyone can help me out?

Thank you!

1 ACCEPTED SOLUTION

jesusnava
Giga Expert

Thank you everyone, here is the answer:

----------------------------------------------------------------

function onLoad() {
//Type appropriate comment here, and begin script below

if ( g_form.getValue("priority") == 1 ) {


g_form.getElement("number").setStyle({color: "red"});


}
}

----------------------------------------------------------------

View solution in original post

16 REPLIES 16

It seems like ServiceNow does not allow for the fount color to be changed.  The code above should work.  I also tried using style with text-decoration-color: red and it did not work.

Here is a wonderful post on ServiceNow Guru that helps with this very question. » Modifying the Label of Form Fields With Client Scripts

 

Regards,

Sachin

Harpal Singh Pa
Tera Contributor

You need to change the field Style :

System UI ---> Field Styles.

There you can create the field style. 

 

Select the Table Name and the Field Name.

In the value you can pass the condition 

eg: javascript:current.caller_id.vip == true.

 

see the attachment for reference. this is an OOB example.find_real_file.png

Hello Harry,

I tried it but did not work =(

Did you try the onLoad Script, if you want in list view, below screenshot will help you. If you want on form load, code I provided earlier works perfectly

 

find_real_file.png