It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Set custom field (select list) value

e t May 18, 2014

Hello!

I've got a customfield_16301 (select list type).

It's got three options: High, Mid, Low.

How do I set an option in customfield_16301 using groovy?

ComponentManager componentManager = ComponentManager.getInstance()

CustomFieldManager customFieldManager = componentManager.getCustomFieldManager()

CustomField customField = customFieldManager.getCustomFieldObject("customfield_16301");

issue.setCustomFieldValue(customField, "High")

Throws NullPtr expections!

Thank you.

1 answer

1 accepted

2 votes
Answer accepted

Hi et,

What is the value of your cstomField object?

e t May 18, 2014

What do you mean?

How do I check that?

Hi e t,

This thread discusses a similar problem:

https://answers.atlassian.com/questions/189262/how-do-i-programmatically-set-values-for-custom-fields-of-type-select-when-creating-an-issue

The solution proposed here should work for all list select type fields.

Try logging the customField variable in your script. What is its value?

Your script should look something like:

CustomField customField = customFieldManager.getCustomFieldObject("customfield_16301");
 
Options options = WebAppsCf.getOptions(null, customField.getRelevantConfig(issue), null);   
 
Option newOption = options.getOptionById("high option"); // Check your option id
 
ModifiedValue mVal = new ModifiedValue(issue.getCustomFieldValue(customField), newOption );
 
customField.updateValue(null, issue, mVal, new DefaultIssueChangeHolder());

e t May 18, 2014

Oh, thanks!

What's "WebAppsCf" ?

// Check your option id - I guess it's 15602

Indeed, you don't need the WebAppCf class. I modified the previous script:

CustomField customField = customFieldManager.getCustomFieldObject("customfield_16301");

OptionsManager optManager = ComponentAccessor.getOptionsManager(); 
Options options = optManager.getOptions(customField.getRelevantConfig(issue), null));   
 
Option newOption = options.getOptionById("high option"); // Check your option id
 
ModifiedValue mVal = new ModifiedValue(issue.getCustomFieldValue(customField), newOption );
 
customField.updateValue(null, issue, mVal, new DefaultIssueChangeHolder());

e t May 18, 2014

Thank you! It worked!

Hi e t,

Can you please mark the answer as accepted? :)

Glad I could help!

Paul Fink Jan 19, 2015

BTW: there is a small typo: Options options = optManager.getOptions(customField.getRelevantConfig(issue), null)); should be Options options = optManager.getOptions(customField.getRelevantConfig(issue))

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Posted in United States

Topic Tuesday: Agile

Another week, another Topic Tuesday!  Agile has been on my mind a lot lately because I've seen good implementations and bad implementations, but now as a Jira admin it matters more to me whether...

40 views 0 0
View post

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you