Need help to setCustomFieldValue for a Select List type

I have a list of Select List type custom fields in which I need to set "Not Required" as default Value while doing "Generate CheckList" step in workflow.

myIssue.setCustomFieldValue(cf, "Not required") -cf is a Select List type custom field.

This kind of code upto JIRA 4.2 version.Now I get ClassCastException.

Can anyone help to setCustomField Value for Select List Type.

4 answers

1 accepted

1 vote
Accepted answer

Select lists store "option" objects, not "strings". You need to find the "Not Required" option in the list of options, and pass that in instead of the string, or create the option from the string as you go.

Thanks Nic.It works after I pass it as Option instead of String.

Now I need to itertate thruough a set of Custom Fields and setCustomFieldValue.It could be a combination fo text,select list etc.

How to check the type of Custom Field and do setCustomFieldValue accordingly.

Can you please give some examples?

Sorry, I missed the comment. I don't know if there's an approved way to do it, but I simply get the class name of the object I get back and execute a set of "if" to handle each possible type. Feels clumsy to me, but I've never had time to look for something better.

If the custom fields expect different values I don't see any alternative...

you have to try something like this

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.crowd.embedded.api.User

MutableIssue issue = issue
ComponentManager componentManager = ComponentManager.getInstance()
CustomFieldManager customFieldManager = componentManager.getCustomFieldManager()
CustomField customField = customFieldManager.getCustomFieldObjectByName("Overall Impact")

Option fieldVal =(Option) issue.getCustomFieldValue(customField)

cfValues['Overall Impact'].value == 'LOW'

cfValues['Overall Impact'] == 'LOW' .

This works good now.


Hi Nic,

cfValues['Overall Impact'] == 'LOW'

I couldnt see any issue in this line.But Workflow is not recognizing this value though 'Overall Impact' is set as LOW.Please help (JIRA version is 5.2)

I'm afraid I don't understand that. I don't know what you're trying to do, or why you mention workflow when you're looking at a field option.

Could you tell us where you're trying to use thi?

Jamie ,

cfValues['Overall Impact'].value == 'LOW' also didnt work out.


It is simple scripted validator.Iam trying to chk if Over All Impact has been set to LOW,then validating it for some more conditions.


it does work. Go to Admin -> Condition Tester and do:

assert cfValues['Overall Impact'].value == 'LOW'

then paste back here the output in red as a comment. Choose an issue where that should evaluate to true.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Feb 07, 2019 in Marketplace Apps

A Timeless Love Story

It started as any story starts, on a normal, rainy day.   Admin meets App, and her name was Klok2, and like any first relationship we were both trying to make it work but neither one knew what...

449 views 8 26
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you