Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Custom field color based on value of another field

Stearns B
Contributor
May 6, 2019

Greetings,

We are looking to base the color of a custom field based on the value or comparison of another field.

Examples:  We have a 'risk' field, 1-5 - based on the number, we would like to change the color of the field

We have an estimated completion date field.  If the estimation is greater than the actual close date, we would want this to be a 'green' or 'red' date to see if the project finished on time or not.  

 

We have ScriptRunner - if there's some simple code for that, this would be the preferred method.  We'd rather not pay for a plugin like 'Rainbow Field' // not sure the cost would be justified.

 

We are running server 8.1 - Thank you!

3 answers

4 votes
Leonard Chew
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 16, 2020

Hi there

It's a bit a hack, but you can do that by injecting CSS-Code through the Scriptrunner (Web-)Fragments feature.

Here is a sample which sets the Story-Point field to "underline & red" as soon as it exceeds the value 13.

 

Condition Script

import com.atlassian.jira.component.ComponentAccessor
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cField = customFieldManager.getCustomFieldObjectsByName("Story Points")[0]
def cFieldValue = (issue.getCustomFieldValue(cField) ?: 0) as long
log.warn('custom field value is: ' +cFieldValue)
(issue.issueType.name =='Story' && cFieldValue>13)

 

Provider class/script

writer.write("<script>var css = '#customfield_10002-val { color: red; font-weight: bold; border-bottom: 2px solid red; }', head = document.head || document.getElementsByTagName('head')[0], style = document.createElement('style');head.appendChild(style);style.appendChild(document.createTextNode(css));</script>")

 

red-story-points.png

 

The result will look like this:

red-story-points-result.png

YARON LEVY
Contributor
June 21, 2020

Hi Leonard, 

How do you change a color of an issue custom field, based on its value, in the issue search table?

 

Thanks

Like Justin likes this
James Park
Contributor
January 19, 2022

What if I do not have ScriptRunner nor know how to use it?

peter-kaufmann
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 12, 2022

Hi @Leonard Chew ,

I want to use your code, but one thing doesn't work. I change the threshold from 13 to a number with decimal seperator like <1.5 but the color change to 2. It seems it's being rounded up. How can I solve this problem? Any idea?

Thanks in advance...

0 votes
Moritz Wagner
Contributor
March 13, 2020

Hello,

 

I'd just be interested, if there was a solution for this problem, and if you are willing to share some hints, because we're facing the same Problem here.

 

Thanks,

Moritz

Angélica Luz
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 16, 2020

Hello Moriz,

Thanks for reaching out to Community!

I checked the ticket and the suggestion is to use Scriptrunner, since there are no features in Jira that allows changing the color of fields based on values.

You can also check this thread in community that may help you achieve that:

Regards,
Angélica

0 votes
Angélica Luz
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 7, 2019

Hi Stearns,

I saw that you created a ticket with our support related to the same question, so to avoid any possible misunderstandings or miscommunication that may arise from discussing the same matter in two different platforms, let's focus on the ticket instead.
Once the ticket is resolved, feel free to share the resolution here to help other people.

Regards,
Angélica

Suggest an answer

Log in or Sign up to answer