- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2024 02:03 AM
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
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2024 03:12 AM
Hi,
Yes it's possible to include a range.
Modify your value into something like this:
javascript: (current.u_score > 0 && current.u_score < 30)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2024 07:34 AM
I can't see any difference between your line and the one I suggested, but great that it worked.
Also, another little detail, make sure that you don't have conflicting styles. In your initial question, the field should be both green and orange if the value was 60.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2024 08:48 AM - edited 07-02-2024 08:50 AM
For some reason on here it shows as : rather than : after the javascript, that's just my mistake
The values we're still working on but the requirements still works as needed.
Thanks again
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2024 02:30 AM
Hi @Alex Saager1,
Yes it is possible to do it. Use Client Script and make sure your field is of type integer. Otherwise convert string to integer, apply following client script inside the function and change the value back to string.
if (newValue === ''){
control.style = 'background-color';
}
if (newValue <= 30){
control.style = 'background-color: red';
} else if (newValue > 30 && newValue <60) {
control.style = 'background-color: orange';
} else if (newValue >= 60 && newValue < 100) {
control.style = 'background-color: green';
}
This should be onChange client script and field name should be selected as score. Also isolate the script
If you found this reply helpful, please mark it as solution and helpful.
Thanks and Regards,
Ehab