ClassCastException

Yogesh Mude November 28, 2017

{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 votes
Tarun Sapra
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 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.

Yogesh Mude November 28, 2017

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
TAGS
AUG Leaders

Atlassian Community Events