You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
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
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.