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());

}{code}

 

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(SelectCFType.java:72) at com.atlassian.jira.issue.customfields.impl.AbstractSingleFieldType.updateValue(AbstractSingleFieldType.java:146) at com.atlassian.jira.issue.fields.ImmutableCustomField.updateValue(ImmutableCustomField.java:426) at com.atlassian.jira.issue.fields.ImmutableCustomField.updateValue(ImmutableCustomField.java:396) at com.atlassian.jira.issue.managers.DefaultIssueManager.updateFieldValues(DefaultIssueManager.java:704) at com.atlassian.jira.issue.managers.DefaultIssueManager.updateIssue(DefaultIssueManager.java:669) at com.atlassian.jira.issue.managers.DefaultIssueManager.updateIssue(DefaultIssueManager.java:655) at com.atlassian.jira.issue.managers.RequestCachingIssueManager.updateIssue(RequestCachingIssueManager.java:214) at com.atlassian.jira.issue.IssueManager$updateIssue$1.call(Unknown Source) at Script101.run(Script101.groovy:69){code}

1 answer

0 vote
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
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published May 30, 2018 in Marketplace Apps

Three tips for boosting your board's efficiency with Story Maps

Trello is one of the most effective tools for driving your sprints. It's customizable for every Agile team and product owners and Scrum masters (SM) love it. However, Agile teams often struggle with:...

844 views 2 9
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