How to change field color based on the field value calculation

Balaram7
Kilo Sage

Hi all,

 

We have a requirement in scoped application. 

There are three fields 1. Net Amount 2. Additional Charges 3. tax amount.

if the calculation of these three fields are equal to Total amount. Then Another field Named Balance field need to be displayed as "OK " and field color needs to be displayed as yellow else it should be displayed as "pending" and field color need to be displayed as "Red " and set the field value as "Pending".

 

Please help me with the  best way to achieve this.

 

Thank you,

Balaram.

6 REPLIES 6

Allen Andreas
Administrator
Administrator

Hi,

Thanks for posting your requirements for us...

What have you tried so far? What have you looked into (documentation wise)?

What is working? What is not working?

We'd love to help you learn.

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

should be something like this in onChange client script wherever you are doing the calculation

you can enhance it as per your requirement.

reference: Background colour in fields

// your logic here

var field = g_form.getControl('balance');
if(condition){
	field.style.backgroundColor = 'yellow'; // sets background color
	field.style.color = 'red'; // sets color to value

}
else{
	g_form.setValue('balance', 'Pending');
	field.style.backgroundColor = 'red'; 
	field.style.color = 'blue'; // sets color to value
}

Regards
Ankur

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

@Balaram 

Hope you are doing good.

Did my reply answer your question?

If my response helped please close the thread by marking appropriate response as correct so that it benefits future readers.

Regards
Ankur

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

@Balaram 

Hope you are doing good.

Did my reply answer your question?

Would you mind closing the thread by marking appropriate response as correct so that it benefits future readers.

Regards
Ankur

 

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