Forums

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

Need to change the background colour of scripted field

Janaki.R
Contributor
October 13, 2021

Hi,

 

 

 

We have a scripted field called "Aging" where we calculate the number of days between Today's date and Star date.

 

Here we need to change the background color of the Aging field based on the below logic.

 

Aging >= 7 days and  <15 days - GREEN

 

Aging >= 15 days and  < 20 days - YELLOW

 

Aging >= 20 days - RED

 

 

 

I am new to scripting. Please provide the script if you have any. Thanks in advance!!!

 

1 answer

1 accepted

1 vote
Answer accepted
Mohamed Benziane
Community Champion
October 13, 2021

Hi,

You can achieve this with a web panel Fragment in scriptrunner.

 

import com.atlassian.jira.component.ComponentAccessor

import com.atlassian.jira.issue.Issue

 
def issue = context.issue as Issue 

def customFieldManager = ComponentAccessor.getCustomFieldManager()

def cField = customFieldManager.getCustomFieldObject("customfield_12603")// put your customfield ID

def cFieldValue = issue.getCustomFieldValue(cField) as Integer
 

def color = ""


if (cFieldValue == 0){

      color = "grey"

}

if (cFieldValue > 0 && cFieldValue <100){

      color = "#FFAE42"

}

if (cFieldValue >= 100){

     color = "#63D13E"

}

// change the customfield id val to your customfield id val.
writer.write("<script>var css = '#customfield_12603-val { color: white;background-color: ${color}; font-weight: bold; border-bottom: 2px solid ${color}; }', head = document.head || document.getElementsByTagName('head')[0], style = document.createElement('style');head.appendChild(style);style.appendChild(document.createTextNode(css));</script>")

Suggest an answer

Log in or Sign up to answer