Is it possible to change the background color of a scripted Field?

Deleted user February 13, 2018

This is my code: 

def A = getCustomFieldValue("Stand")?.value
if (A == "1") {
return "ROT"
}
if (A == "2") {
return "ROT"
}
if (A == "3") {
return "ROT"
}
if (A == "4") {
return "Gelb"
}
if (A == "5") {
return "Gelb"
}
if (A == "6") {
return "Gelb"
}
if (A == "7") {
return "GRÜN"
}
if (A == "8") {
return "GRÜN"
}
if (A == "9") {
return "GRÜN"
}
else {
return null
}

 

And what I want to do is change the background color if the event is true. 

 

like If field A is "1" the change background color of the field to "Red" and write the word "RED".

 

Can I do this with scriptrunner/groovy? 

2 answers

1 accepted

2 votes
Answer accepted
Alexey Matveev
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.
February 13, 2018

You can provide a custom template for the field. the custom template would look like this

#if ( $value == 1 )
<font color="red">$value</font>
#else
<font size="3" color="blue">$value</font>
#end

You can read more info here:

https://scriptrunner.adaptavist.com/5.0.4/jira/scripted-fields.html#_custom_templates

Deleted user February 13, 2018

fehler_Farber_rot.png

I am getting this error. 

I am adding this in the inline script.

Am i missing something? do I need to define anything. 

Alexey Matveev
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.
February 13, 2018

Where do you write your script? If you choose custom template then there are two text fields: Custom Template and Inline Script. In inline script you just return a value. Your script 

def A = getCustomFieldValue("Stand")?.value
if (A == "1") {
return "ROT"
}
if (A == "2") {
return "ROT"
}
if (A == "3") {
return "ROT"
}
if (A == "4") {
return "Gelb"
}
if (A == "5") {
return "Gelb"
}
if (A == "6") {
return "Gelb"
}
if (A == "7") {
return "GRÜN"
}
if (A == "8") {
return "GRÜN"
}
if (A == "9") {
return "GRÜN"
}
else {
return null
}

goes to inline script.

In the Custom template you already use the value which is return by your script. The value is available under $value. You just define the  colour for the return values like 

#if ( $value.equals("ROT") )
<font color="red">$value</font>
#end
#if ($value.equals("Gelb"))
<font color="yellow">$value</font>
#end

and so on.

Deleted user February 13, 2018

Yes I got that, I was just about to reply :) 

thank you very much. 

Can I only change the font color? Because I would lick to change the background color. is that also possible?

Alexey Matveev
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.
February 13, 2018

You can use any html tags. 

0 votes
Stearns B May 13, 2019

Hi @[deleted] 

We're looking to do something similar at our organization - do you have the full ScriptRunner code that you used?

 

Thank you!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events