Document toolboxDocument toolbox

How to append values to multi-select fields

Goal

This section shows the instructions to use the ScriptRunner together with Lookup Manager to append values to multi-select fields.

Pre-requisites

✔️ Create a lookup table
✔️ Lookup Table Edit permission
✔️ ScriptRunner installed

Demonstration

Instead of overwriting the existing field value, I would like to append the value to a multi-select custom field.

Step 1: Create a Lookup Table

Project Key

Product

Product Owner

Project Key

Product

Product Owner

ACC

Attachment Checker for Confluence

Adam

MCHART

Multiple Filters Chart Gadgets

Bob

ACJ

Attachment Checker for Jira

Adam

LOOKUP

Lookup Manager

Adam

CQL

CQL for Confluence

Adam

Step 2: Use the lookup ScriptRunner function to search for values and append to the multi-select custom field

a) Add a ScriptRunner post function

b) Select Custom Script post-function

c) Paste the following code into the Inline script field. This script will look up the App Management Table and search the column Product Owner which matches Adam. For those matching rows, it will collate All the corresponding values in the Project Key column. Then it will append the values to Product List which is a multi-select custom field.

import com.atlassian.jira.component.ComponentAccessor import com.onresolve.scriptrunner.runner.customisers.PluginModule import com.onresolve.scriptrunner.runner.customisers.WithPlugin import com.akelesconsulting.jira.plugins.rest.LookupService @WithPlugin("com.akelesconsulting.jira.plugins.LookupManager") @PluginModule LookupService lookupService int tableId = lookupService.getTableIdByName("App Management Table") def matchingValuesArray = lookupService.lookup(tableId, "Product Owner", "Adam", "Project Key") def customFieldManager = ComponentAccessor.customFieldManager // Name of the multi-select custom field to change def customFieldName = "Product List" def cf = customFieldManager.getCustomFieldObjectByName(customFieldName) def cfValue = issue.getCustomFieldValue(cf) as ArrayList if (cfValue == null) { cfValue = new ArrayList() } def optionsManager = ComponentAccessor.getOptionsManager() def newValues = cfValue matchingValuesArray.each { val -> def option = optionsManager.getOptions(cf.getRelevantConfig(issue)).find {it.value == val.trim()} newValues += [option] } issue.setCustomFieldValue(cf, newValues)

Learn More