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

Set custom field (select list) value

e 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

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

2 votes
Answer accepted
BenjiI
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.
May 18, 2014

Hi et,

What is the value of your cstomField object?

e May 18, 2014

What do you mean?

How do I check that?

BenjiI
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.
May 18, 2014

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.

BenjiI
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.
May 18, 2014

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

BenjiI
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.
May 18, 2014

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 May 18, 2014

Oh, thanks!

What's "WebAppsCf" ?

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

BenjiI
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.
May 18, 2014

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 May 18, 2014

Thank you! It worked!

BenjiI
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.
May 18, 2014

Hi e t,

Can you please mark the answer as accepted? :)

Glad I could help!

Paul Fink January 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))

TAGS
AUG Leaders

Atlassian Community Events