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

This widget could not be displayed.
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 Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Published Jul 25, 2018 in Marketplace Apps

Jira Cloud and Bitbucket Cloud Integration with Microsoft Teams

One of the newest products in the Microsoft family - Microsoft Teams,  is a chat-based hub for teamwork that integrates all the people, content, and tools your team needs to be more engaged and ...

730 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