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

This widget could not be displayed.

See Hennings answer (and give him a vote):

This widget could not be displayed.

Thanks! That worked.

This widget could not be displayed.

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 Aug 22, 2018 in Marketplace Apps

How a Marketplace app tech team is achieving gender diversity

Hello! My name is Genevieve Blanch, and I'm the Marketing Manager at RefinedWiki, creators of apps to give teams the tools to customize Atlassian platforms. Currently, 44% of the tech team at Re...

492 views 3 18
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