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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published 11 hours ago in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

35 views 0 3
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