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

viswav
Giga Contributor

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

5 REPLIES 5

Bhavya11
Kilo Patron

hi @viswav 

 

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

viswav
Giga Contributor

not working

Anurag Tripathi
Mega Patron
Mega 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
Kilo Patron
Kilo Patron

Hi @viswav ,

 

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.