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(SelectCFType.java:69)
at com.atlassian.jira.issue.customfields.impl.AbstractSingleFieldType.createValue(AbstractSingleFieldType.java:161)
at com.atlassian.jira.issue.fields.CustomFieldImpl.createValue(CustomFieldImpl.java:831)
at com.atlassian.jira.issue.fields.CustomFieldImpl.updateValue(CustomFieldImpl.java:505)
at com.atlassian.jira.issue.fields.CustomFieldImpl.updateValue(CustomFieldImpl.java:487)
at com.atlassian.jira.issue.fields.OrderableField$updateValue.call(Unknown Source)
at Script6.run(Script6.groovy:16)

 

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?

 

Thanks!

 

 

3 answers

See Hennings answer (and give him a vote):

https://answers.atlassian.com/questions/259390

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,

Nishant

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Oct 31, 2018 in Marketplace Apps

Marketplace Spotlight: Zephyr

Hello Atlassian Community! Each month, we run a series of Spotlights to highlight Marketplace vendors and apps that our team thinks this Community would find valuable. In last month's Spotlig...

320 views 0 1
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