I've created a script that looks like this:
String customField = getCustomFieldValue("custom field") Double index = Double.parseDouble(customField) if (index <= 1) { return "<div style='color:green;'><b>Low</b></div>" } else if (index > 1 && index < 2) { return "<div style='color:green;'><b>Normal</b></div>" } else if (index >= 2 && index < 4) { return "<div style='color:#FFBF00;'><b>High</b></div>" } else if (index > 4) { return "<div style='color:red;'><b>MAX</b></div>" } else { return "<div style='color:red;'><b>ERROR</b></div>" }
This script works great and exactly as I've intended. The correct formatting displays when I show the column on a View screen, in a column in the Issue Navigator, in an exported Excel file, and in a column within a gadget.
However, I'd like to be able to use the values in this field as the basis for a gadget, such as the basis for an Issue Statistics gadget. However, when doing this, the value in the gadget isn't returned as the formatted text (for example, green bolded "Low"), but appears as a string of HTML code. Is there a way to only return the text without the full HTML code when basing a gadget on this field?
Thank you in advance for your help here!
This is untested. I haven't even inputted it into a system, I'm just trying to give you an idea of what I mean. You should separate the styling from the values.
String customField = getCustomFieldValue("custom field") Double index = Double.parseDouble(customField) if (index <= 1) { return "Low" } else if (index > 1 && index < 2) { return "Normal" } else if (index >= 2 && index < 4) { return "High" } else if (index > 4) { return "MAX" } else { return "ERROR" }
#if ($value = "Low") <div style='color:green;'><b>$value</b></div> #elseif ($value = "Normal") <div style='color:green;'><b>$value</b></div> #elseif ($value = "High") <div style='color:#FFBF00;'><b>$value</b></div> #elseif ($value="Max") <div style='color:red;'><b>$value</b></div> #else ($value="Error") <div style='color:red;'><b>$value</b></div> #end
Thanks for your answer, Steven. This should help point me in the right direction. Appreciate your help!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Doesn't appear to work anymore, the formatted HTML is encased in a string when used as a custom field, so you see the raw HTML on the issue screen. :/
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You should not be using raw HTML to format the field value with a DIV and styling. You should be exploiting the 'Template' function of your scripted field to achieve the look and feel, and the field-value should be NOTHING except the value.
https://scriptrunner.adaptavist.com/latest/jira/scripted-fields.html#_custom_templates
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.