Set field styles based on value

Alex Saager1
Tera Contributor

Hi community,

 

I'm trying to set a field style based on a numerical value and wondered if this was even possible.

 

So I have a custom field on the cmdb_ci_computer called score which will be a number and they way I envision this working is if the value is if the value is...

 

less than 30 highlight the field red

between 30 - 60 orange 

between 60 - 100 green.

 

Is what I'm trying even possible?

 

Many thanks,

Alex

1 ACCEPTED SOLUTION

Hi,

Yes it's possible to include a range.

Modify your value into something like this:

javascript&colon; (current.u_score > 0 && current.u_score < 30)

 

View solution in original post

7 REPLIES 7

Valmik Patil1
Kilo Sage

Hello @Alex Saager1 ,

 

There are two ways,

1. Using client script :

 

var myField = "<your field name>';

var ctrl = g_form.getControl(myField);

if(<your condition>=="<certain value>") {

ctrl.style.backgroundColor = 'red';

ctrl.style.color ='black';

g_form.setVisible('<yourfield>',true);

}

2. System UI > Field Styles.

 - Using field styles also you can do.

 Screenshot 2022-12-28 at 7.48.34 PM.png

 

Thanks,

Valmik Patil

Hi @Valmik Patil1 

 

Thanks for this, is it possible to do a between operator on the value so for example if the number is between 1 and say 10, i tried the below but it didn't work:

 

AlexSaager1_1-1719913600861.png

 

Hi,

Yes it's possible to include a range.

Modify your value into something like this:

javascript&colon; (current.u_score > 0 && current.u_score < 30)

 

Hi @OlaN 

Slightly changed it to:
javascript&colon; (current.u_score > 0 && current.u_score < 30)

 

But that worked perfectly, thank you 🙂