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

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


1 badge earned


Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!


Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.


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!


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
Community Members
Community Events
Community Groups

How do I programmatically set values for custom fields of type select when creating an issue?

I have tried using:

IssueInputParameters.addCustomFieldValue(customField.getIdAsLong(), issue.getCustomFieldValue(customField).toString())

But this is causing errors in my CreateValidationResult

6 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

3 votes
Answer accepted

This is how I've been doing it, it works well enough for me:

CustomField customField = customFieldManager.getCustomFieldObject(customFieldId);

Options options = WebAppsCf.getOptions(null, customField.getRelevantConfig(issue), null);	

Option newOption = options.getOptionById(newOptionId);

ModifiedValue mVal = new ModifiedValue(issue.getCustomFieldValue(customField), newOption );

customField.updateValue(null, issue, mVal, new DefaultIssueChangeHolder());

do I have to use customfield.updateValue? Will a direct implementation of Issue.setCustomFieldValue not work?

By the way I'm guessing that this method will work for setting values of any custom field type that consists of options?

I don't see Issue.setCustomFieldValue in the api's which is probably why i didn't use it But if that method does exist, I think it would work, the important thing is you set the new value as a proper Option object.

Kyle I used your method and it worked! Thanks =)))

It hasn't not worked for me yet (:

Yes, select, multi-select, radio and check boxes will work. You might need to tweak it for cascading-select. The same principle will work for other field types too - for dates, use a timestamp, for user fields, a user object, versions for version type fields etc.

However, that code looks like it overrides the current value with a single value. For multi fields, I think you need to pass it a list of options. If you want to update, rather than overwrite, you'll need to fetch the current list and add to it (obviously, for "create", that's irrelevant)

def myCustomField = getCustomFieldObjects(issue).find { == "My multi-select field"

// just passing a values as List/Map.
issue.setCustomFieldValue(myCustomField, [value])

// e. g.
def values = issue.getCustomFieldValue(myCustomField)
Option it ->

Reading an setting values is documented well in this book linked below.


It also includes very good examples of how to work with Custom Fields of the "Checkboxes" type - which is hard to find documentation for (see page 107-ish).

This is my variant of doing this but I'm not really happy yet. This also enables you to set disabled options so beware of this. 

// Get the project the issue should be created in.
def curPrj = projectManager.getProjectObjByKey("Project I want to set");

// Set the issuetype that should be used.
def issueType = issueTypeSchemeManager.getIssueTypesForProject(curPrj).find{"Issue Type I want to set"};
def issueContext = new IssueContextImpl(curPrj, issueType);
def fieldConfig = customfield.getRelevantConfig(issueContext);
def options = optionsManager.getOptions(fieldConfig); 
def optionToSelect = options.find { it.value == "Select Option I want to set" }; 
return optionToSelect.getOptionId();

Then in issue input parameters remember to treat it as a string.

Sorry if this is a very dumb question but how to I declare the optionsManager?  

ah i got it:


import com.atlassian.jira.component.ComponentAccessor
def optionsManager = ComponentAccessor.getOptionsManager()

My example of code here

Your code is not related to the select list options!

Niclas, yes but it may help you with an example of modern code that is not from 2013. It also represents Validation technique which is needed if you want your code to be safe.

But there's not a lot of point in giving code that doesn't have anything to do with the question.

mutableIssueParent.setCustomFieldValue(fieldIssue, value);

FieldLayoutItem fieldLayoutItem = ComponentAccessor.getFieldLayoutManager().getFieldLayout(mutableIssueParent).getFieldLayoutItem(fieldIssue);

DefaultIssueChangeHolder issueChangeHolder = new DefaultIssueChangeHolder();

Map<String, ModifiedValue> modifiedFields = mutableIssueParent.getModifiedFields();

final ModifiedValue modifiedValue = (ModifiedValue) modifiedFields.get(fieldIssue.getId());

fieldIssue.updateValue(fieldLayoutItem, mutableIssueParent, modifiedValue, issueChangeHolder);
// Dont forget this to search the latest elements updated
IssueIndexingService is=ComponentAccessor.getComponent(IssueIndexingService.class);
try {
} catch (IndexException e) {
log.error("Erreur reIndexIssue ",e);

0 votes

Well, it would - you seem to be using strings, when select list fields expect "option" objects.

Unfortunately the only options I have when using the addCustomFieldValue function is (Long , String) or (String, String) , I dont have a choice of (Long, Option). Is there some other way I can get these custom fields populated in my IssueInputParameters variable?

If not what's the correct way to populate these fields after the issue has been created? I've tried using

IssueResult.getIssue().setCustomFieldValue(customField, Option ) but I dont know what to put to get the correct option for the field.

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question


Atlassian Community Events