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,560,262
Community Members
 
Community Events
185
Community Groups

ScriptRunner - Set a select list custom field value

I need to update a select list (single choice) custom field as part of a workflow transition so I have tried the code provided in the link below

https://docs.adaptavist.com/sfj/set-a-select-list-custom-field-value-11468840.html

Unfortunately I get the error message belowerror.PNG

Does anyone know how to fix this?

My code is

 

import com.atlassian.jira.component.ComponentAccessor
def cfSelect = ComponentAccessor.customFieldManager.getCustomFieldObjectsByName("Change Request Priority")
def cfConfig = cfSelect.getRelevantConfig(issue)
def value = ComponentAccessor.optionsManager.getOptions(cfConfig)?.find {
    it.toString() == '5 - Urgent'
}
issue.setCustomFieldValue(cfSelect, value)

 

We are using Jira Software Data Center 8.20.8 and ScriptRunner 7.1.0

 

Thank you for your help

1 answer

1 vote
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Nov 16, 2022

Your error is on this line:

def cfSelect = ComponentAccessor.customFieldManager.getCustomFieldObjectsByName("Change Request Priority")

Notice the 's' in getCustomFieldObjecsByName 

This, and the error message indicating that a "getRelevantConfig"  is no application to "Collection" means that you have a collection of custom fields. Not a single custom field object

Change that line to

def cfSelect = ComponentAccessor.customFieldManager.getCustomFieldObjectsByName("Change Request Priority")[0]

 But also, it's better to use an explicit method/property to compare objects rather than the generaic "toString"

Here is a fully revised version of your script:

import com.atlassian.jira.component.ComponentAccessor
def cfSelect = ComponentAccessor.customFieldManager.getCustomFieldObjectsByName("Change Request Priority")[0]
def cfConfig = cfSelect.getRelevantConfig(issue)
def value = ComponentAccessor.optionsManager.getOptions(cfConfig)?.find {
it.value == '5 - Urgent'
}
issue.setCustomFieldValue(cfSelect, value)

Dear @Peter-Dave Sheehan 

Thank you for your help. It is highly appreciated. 

I will test the new script as soon as possible.

Worked nicely for me too.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events