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

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

Where i need to configure field name in onload script?

Hi,

yes onload of the table on which field is present

Regards
Ankur

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

@lucky 

Hope you are doing good.

Did my reply answer your question?

If so, please my response as correct & helpful so that the question will appear as resolved for others who may have a similar question in the future.

Thanks!
Ankur

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