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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,555,371
Community Members
 
Community Events
184
Community Groups

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

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

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events