Post-function to set custom field that is a single select list?

I'm trying to right a groovy script to conditionally set a customfield, but I'm getting an error. I can't seem to find an example that matches my need. Can anybody help?

Here's my attempt:

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.util.IssueChangeHolder
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue
MutableIssue myIssue = issue

ComponentManager componentManager = ComponentManager.getInstance()
CustomField customField = componentManager.getCustomFieldManager().getCustomFieldObjectByName('Integration Checked')
IssueChangeHolder changeHolder = new DefaultIssueChangeHolder();
customField.updateValue (null, myIssue, new ModifiedValue(myIssue.getCustomFieldValue(customField), 'Needed'), changeHolder)


The error I am getting is:

java.lang.ClassCastException: java.lang.String cannot be cast to com.atlassian.jira.issue.customfields.option.Option
at com.atlassian.jira.issue.customfields.impl.SelectCFType.getDbValueFromObject(
at com.atlassian.jira.issue.customfields.impl.AbstractSingleFieldType.createValue(
at com.atlassian.jira.issue.fields.CustomFieldImpl.createValue(
at com.atlassian.jira.issue.fields.CustomFieldImpl.updateValue(
at com.atlassian.jira.issue.fields.CustomFieldImpl.updateValue(
at com.atlassian.jira.issue.fields.OrderableField$ Source)


It sounds like I'm dealing with the custom field as if it was simple text, and not a select list. But, how do I fix it?





3 answers

See Hennings answer (and give him a vote):

Thanks! That worked.

Please tell me what is wrong with this script? It is returning NULL.

Requirement: Need to update the value of a custom field from NULL to the value specified in the script.


import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.fields.CustomField;

def fieldid = 14601L //field id; currently having null value
def dbValue = "8.0.8" //New value to be assigned to the custom field

def issue = ComponentAccessor.getIssueManager().getIssueByCurrentKey("TIK-3039"); //issue in JIRA
MutableIssue myIssue = issue;

def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(fieldid); //Identification of Custom Field Object

myIssue.setCustomFieldValue(customField,dbValue); //updating the value from "Null" to the value declared above "dbValue"


Best regards,


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...

441 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