Skip to end of banner
Go to start of banner

WIP: Select List (single choice) options description+id in Power Scripts using SIL Groovy Connector/Runner

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

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

  1. 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.

  2. Once the SIL Groovy Connector is installed, you will end up with a description as shown in the attached capture:

image-20240306-140615.png
  1. 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;
  1. From any of your SIL scripts, you can now call the Groovy script using the executeGroovyScript and readFromTextFile 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"));
image-20240307-135003.png

Notes:

  • The returned value is a regular, comma-separated String (not a String array), so you must handle it correctly according to your needs.

  • No labels