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

John Fisher March 30, 2015

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

2 votes
Udo Brand
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 30, 2015

See Hennings answer (and give him a vote):

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

0 votes
Nishant Kansal March 30, 2016

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

0 votes
John Fisher April 1, 2015

Thanks! That worked.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events