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?
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
I am getting this error.
I am adding this in the inline script.
Am i missing something? do I need to define anything.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You can use any html tags.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @[deleted]
We're looking to do something similar at our organization - do you have the full ScriptRunner code that you used?
Thank you!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.