Interested in a ServiceNow event built for developers? Registration for now[dev]26 is officially open!

Each time the state field changes, number fields background colour should be changed

Not applicable

Each time the state field changes, number fields background colour should be changed

5 REPLIES 5

Bhavya11
Mega Patron

hi @Community Alums 

 

you can try below code 

 

function onLoad() {
   //Type appropriate comment here, and begin script below
    var element = g_form.getElement('number');
   if (g_form.getValue('state') == 3) {
        element.style.backgroundColor = "red";
    }else if(g_form.getValue('state') == 1){
		element.style.backgroundColor = "green";
	}
}

 

 

 

If my response proves useful, please indicate its helpfulness by selecting "Accept as Solution" and " Helpful."

 

 

Thanks,

BK


Regards
BK
LinkedIn: https://www.linkedin.com/in/bhavyashree-karanth-55032a121
YouTube: https://www.youtube.com/@NowWithBhavya

Not applicable

not working

Anurag Tripathi
Giga Patron

You can use field styles for the sale. that would work on List view as well as form.

Define field styles (servicenow.com)

-Anurag

SN_Learn
Mega Patron

Hi @Community Alums ,

 

check the below:

https://www.servicenow.com/community/developer-forum/client-script-to-change-the-background-color-of...

----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.