ClassCastException Edited

{code}String customerValue = epic.getCustomFieldValue(customerField);
String frrNumberValue = epic.getCustomFieldValue(frrNumberField);

//First Set the value of PFRR i.e customer & FRR number from the above string
if(customerValue!= null)
System.out.println("@@@@@@ Customer Value " +customerValue)
Options options = ComponentAccessor.getOptionsManager().getOptions(customerField.getConfigurationSchemes().listIterator().next().getOneAndOnlyConfig());
def optionToSelect = options.find { it.value == customerValue};
myIssue.setCustomFieldValue(customerField, optionToSelect.getOptionId().toString());
ComponentAccessor.getIssueManager().updateIssue(appUser, myIssue, EventDispatchOption.DO_NOT_DISPATCH, false);
System.out.println("@@@@@@ Issue Key " +myIssue.getKey());



I tried with this code but getting the below error 

{code}2017-11-28 14:54:37,146 WARN [common.UserScriptEndpoint]: Script console script failed: 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.updateValue( at com.atlassian.jira.issue.fields.ImmutableCustomField.updateValue( at com.atlassian.jira.issue.fields.ImmutableCustomField.updateValue( at com.atlassian.jira.issue.managers.DefaultIssueManager.updateFieldValues( at com.atlassian.jira.issue.managers.DefaultIssueManager.updateIssue( at com.atlassian.jira.issue.managers.DefaultIssueManager.updateIssue( at com.atlassian.jira.issue.managers.RequestCachingIssueManager.updateIssue( at com.atlassian.jira.issue.IssueManager$updateIssue$ Source) at{code}

1 answer

0 votes
Tarun Sapra Community Champion Nov 28, 2017

What's the type of your customField (is it a select drop-down?), as from your code the first line itself looks incorrect.

You have written

String customerValue = epic.getCustomFieldValue(customerField);

In the above code statement epic.getCustomFieldValue will return an type "Option" if the field is of type "select drop down" and you are trying to map it to an String and thus you see an Exception.

Thanks for your response.

I have resolved that issue...the scenario is we want to update all the issues that are there in out instance with specific type with the two fields.

if i update some stuff of code on that create issue transition as post function then it is updating that particular custom fields values but we want all the issues which is created in epic and linked issue of that particular issue type

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

478 views 8 28
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