Power Scripts and the SIL Engine don't include (at the moment this article has been written) a routine to obtain the option's descriptions and IDs (hence the mapping between both). However, due to the powerful SIL Groovy Connector/Runner app, we can rely on the Groovy language to directly access Jira's components and retrieve such information that can be returned as data for use in any of our SIL scripts.
\uD83D\uDCD8 Instructions
Install the SIL Groovy Connector (Runner) - Atlassian Marketplace listing: https://marketplace.atlassian.com/apps/1220177/sil-groovy-connector?hosting=datacenter&tab=overview - this will enable the executeGroovyScript() SIL routine.
Once the SIL Groovy Connector is installed, you will end up with a description as shown in the attached capture:
Using the SIL Manager, create a new Groovy script (for naming convention purposes, please ensure the filename ends with a .groovy extension) and copy/paste the code snippet below. E.g., Groovy/getOptionsID_Desc.groovy
On line #4, you need to set your customfield_id (that represents the Select list - single choice field)
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.fields.CustomField CustomField field = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_XXXXX") def fieldOptions = ComponentAccessor.optionsManager.getOptions(field.getRelevantConfig(issue)) def fieldOptionsArray = []; if (fieldOptions != null) { for (i in fieldOptions) { def valueX = ComponentAccessor.optionsManager.getOptions(field.getRelevantConfig(issue))?.find {it.getValue() == i.toString()}.getOptionId() fieldOptionsArray.add(valueX.toString() + "|" + i.toString()); } } return fieldOptionsArray;
From any of your SIL scripts, you can now call the Groovy script using the
executeGroovyScript
andreadFromTextFile
SIL routines. The returned values are formatted as “ID|description
" (pipe-separated) for each option in the Select list field. Please refer to the example below.
return executeGroovyScript(readFromTextFile("Groovy/getOptionsID_Desc.groovy"));
Notes:
The returned value is a regular, comma-separated String (not a String array), so you must handle it correctly according to your needs.