I want to color code the options of a single select custom field on a Jira service desk form, is it possible to do so using scriptrunner?
Here is the fragment that I created which is not working
I chose Show a web panel, and Location as "servicedesk.portal.header"
import com.atlassian.jira.component.ComponentAccessor
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cField = customFieldManager.getCustomFieldObjectsByName("Field 1")[0]
def cFieldValue = issue.getCustomFieldValue(cField)
def optionsToColor = ["Option1", "Option2", "Option3"] // List of option values to color
return (cFieldValue in optionsToColor)
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import groovy.xml.StreamingMarkupBuilder
@WithPlugin("com.onresolve.jira.groovy.groovyrunner")
@PluginModule
def renderer
def issue = ComponentAccessor.getIssueManager().getIssueObject("ISSUE-KEY")
def script = '''
<script>
var css = '.js-dropdown-menu .active[data-label="Option1"] { background-color: yellow; }' +
'.js-dropdown-menu .active[data-label="Option2"] { background-color: orange; }' +
'.js-dropdown-menu .active[data-label="Option3"] { background-color: red; }';
var head = document.head || document.getElementsByTagName('head')[0];
var style = document.createElement('style');
head.appendChild(style);
style.appendChild(document.createTextNode(css));
</script>
'''
writer.write(script)
Please tell me where am I going wrong