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.
Community moderators have prevented the ability to post new answers.
Hi et,
What is the value of your cstomField object?
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try logging the customField variable in your script. What is its value?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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());
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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());
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi e t,
Can you please mark the answer as accepted? :)
Glad I could help!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
BTW: there is a small typo: Options options = optManager.getOptions(customField.getRelevantConfig(issue), null)); should be Options options = optManager.getOptions(customField.getRelevantConfig(issue))
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.