Forums

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

How can I return the Field value in color?

Anele Mpungose
August 19, 2024

I wrote a script for a radio button custom field to change the color when an option is chosen. I previewed an issue, and it returned the value, but it is not changing the color on the view screen.

3 answers

1 accepted

1 vote
Answer accepted
Sebastian Krzewiński
Community Champion
August 19, 2024

Hi @Anele Mpungose 

 

Whee did you wrote that script? can you share your code to review it?

 

Regards,

Seba

Anele Mpungose
August 19, 2024

the script is on Scripted fields

Screenshot 2024-08-19 154225.png

Sebastian Krzewiński
Community Champion
August 20, 2024

Hi! Below script that I wrote few years ago for similar thing. It worked. Maybe this will help you to solve this.

import com.atlassian.jira.component.ComponentAccessor


def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cField = customFieldManager.getCustomFieldObject("customfield_11702")
def cFieldValue = issue.getCustomFieldValue(cField)

if(cFieldValue == 'R') {
return "<div style='color:red;background-color:red;width:20px;border-radius:50%;'>" + cFieldValue + "</div>"
}
if(cFieldValue == 'G') {
return "<div style='color:green;background-color:green;width:20px;border-radius:50%;'>" + cFieldValue + "</div>"
}
if(cFieldValue == 'Y') {
return "<div style='color:yellow;background-color:yellow;width:20px;border-radius:50%;'>" + cFieldValue + "</div>"
}

Regards,

Seba 

0 votes
Anele Mpungose
August 20, 2024

I Came out right. My configurations on the screens were incorrect

 

0 votes
Marc -Devoteam-
Community Champion
August 19, 2024

Hi @Anele Mpungose 

I think you need to use Scriptrunner fragments for this.

https://docs.adaptavist.com/sr4js/latest/features/fragments 

Anele Mpungose
August 19, 2024

Hi @Marc -Devoteam- I went through the documentation and attempted to use Fagments to solve this issue but I am lost. Do you have an example that I can maybe use?

 

Suggest an answer

Log in or Sign up to answer