Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

What is the best approach to populate a Jira Select List with dynamic data

serge calderara
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 21, 2021

Dear all,

We have a custom field named for instance List Of BD which is a single select list box. Usually we configure that list with static data directly from the configure section of the field.

Now in our new case, those data are coming from an external source that we have access to which render a list of DB in an array.

What we are looking for is the best way with script runner script to add those value to the list if it is not existing already.

What is the proper way to do this ? sample will help

regards

2 answers

1 accepted

Suggest an answer

Log in or Sign up to answer
0 votes
Answer accepted
Leo
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 21, 2021

Hi @serge calderara,

I used below code to update select list field options list dynamically(my use case was different and I was picking value from internal jira ticket field, so used listener in my case)

 

import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def optionsManager = ComponentAccessor.getOptionsManager()
def issueService = ComponentAccessor.getIssueService()

def value = //value to update in options list
def updField = customFieldManager.getCustomFieldObjectByName("Field name for which you want to add new values/options")

def fieldConfig = updField.getRelevantConfig(issue)
def currentOptions = optionsManager.getOptions(fieldConfig)
def newSeqId = currentOptions*.sequence.max() - 1
def option = optionsManager.createOption(fieldConfig, null, newSeqId, value)

def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issueInputParameters = issueService.newIssueInputParameters()
issueInputParameters.with {
addCustomFieldValue(updField, option.optionId.toString())
addCustomFieldValue(value, null)
}
def updateValidationResult = issueService.validateUpdate(currentUser, issue.id, issueInputParameters)
if (updateValidationResult.isValid()) {
issueService.update(currentUser, updateValidationResult)
}
else {
log.warn("Failed to update ${updateValidationResult.errorCollection}")
}

 

BR,

Leo

0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 21, 2021

If the external database is of a supported type, then I'd reach for a database-picker field that is built into Scriptrunner - see https://docs.adaptavist.com/sr4js/latest/features/script-fields/built-in-script-fields/database-picker

TAGS
AUG Leaders

Atlassian Community Events