Field styles are not working on form but its working on list view

lucky6
Tera Contributor

Hello,

I have one field on form and I want to show it in red colour when the record is in-active.I have added styles in configure styles but its working only in list view not on form..can anyone suggest whats wrong here..

Table :xyz

Field name : Name

Value : javascript: current.status='Active'

Style : background-color:red

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

if you give value then it would apply only on list

to make it work on form do this

create onLoad client script

function onLoad() {

var control = g_form.getControl('status');

var status = g_form.getValue('status');

if(status.toString() == 'true'){

control.style.color = 'blue'; // to set the color of field

control.style.backgroundColor = "red";   // to set the background color

}

}

Regards
Ankur

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

View solution in original post

5 REPLIES 5

Michael_Martin
Tera Contributor

In Forms, it actually only sets the background color when it's not an interactive field. That means..
If you set the target field to "read only" your configured field style would work in forms too.

If it needs to be editable. Then there is only the way via client script.