Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Groovy Script Cast Exception


As m getting the list of incomplete issues from the sprint, i want to reset the sprint field of those incomplete issues to null.

i tried with the below code but getting error.


import com.atlassian.jira.bc.issue.IssueService;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.greenhopper.service.rapid.view.RapidViewService;
import com.atlassian.greenhopper.service.sprint.Sprint
import com.atlassian.greenhopper.web.rapid.chart.HistoricSprintDataFactory
import com.onresolve.scriptrunner.runner.customisers.PluginModuleCompilationCustomiser
import com.atlassian.greenhopper.service.sprint.SprintManager
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import groovy.transform.BaseScript
import java.util.ArrayList;
import java.util.Collection;


@BaseScript CustomEndpointDelegate customEndpointDelegate

String sprintId = event.sprint.getId();
//def sprint = event.sprint;

ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
System.out.println("Sprint Name : " + event.sprint.getName() );

def sprintManager = PluginModuleCompilationCustomiser.getGreenHopperBean(SprintManager)
def historicSprintDataFactory = PluginModuleCompilationCustomiser.getGreenHopperBean(HistoricSprintDataFactory)
def rapidViewService = PluginModuleCompilationCustomiser.getGreenHopperBean(RapidViewService)

def userManager = ComponentAccessor.getUserManager()
def issueService = ComponentAccessor.getIssueService()

def closedSprint = sprintManager.getSprint(sprintId.toLong()).value
def view = rapidViewService.getRapidView(user, closedSprint.rapidViewId).value
def sprintContents = historicSprintDataFactory.getSprintOriginalContents(user, view, closedSprint)
def sprintData = sprintContents.value
def sprintField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Sprint");

if(sprintData != null)

def incompleteIssues =sprintData.contents.issuesNotCompletedInCurrentSprint*.issueId;
System.out.println("Incomplete Issues : " + incompleteIssues);
if(incompleteIssues != null)
for(int i=0;i < incompleteIssues.size();i++ )
//String value = null;
System.out.println("Issue Key : " + incompleteIssues.get(i).toString());
MutableIssue mutableObject = (MutableIssue)incompleteIssues;
mutableObject.setCustomFieldValue(sprintField, null);
ComponentAccessor.getIssueManager().updateIssue(user, mutableObject, com.atlassian.jira.event.type.EventDispatchOption.ISSUE_UPDATED, false);



2019-04-30 20:48:33,859 http-nio-8712-exec-13 ERROR admin 1248x1199x1 18hxn2v 0:0:0:0:0:0:0:1 /rest/greenhopper/1.0/sprint/107/complete [c.o.scriptrunner.runner.AbstractScriptListener] Script function failed on event:, file: <inline script>
org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '[10601, 11001]' with class 'java.util.ArrayList' to class 'com.atlassian.jira.issue.MutableIssue' due to: groovy.lang.GroovyRuntimeException: Could not find matching constructor for: com.atlassian.jira.issue.MutableIssue(java.lang.Long, java.lang.Long)


1 answer

0 votes
Payne Community Leader May 01, 2019

You're attempting to cast your list of issues, rather than the current issue in the loop, to one MutableIssue object.

Rather than

MutableIssue mutableObject = (MutableIssue)incompleteIssues;

You need something like

MutableIssue mutableObject = (MutableIssue)incompleteIssues.get(i);

...I think it is even worse... you try to cast a list of issueIDs to one issue ??:-(

You should for all the issueIDs in the list, instantiate first the issue (and cast it to MutabelIssue) , and then ....

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Jira

Admins, notify your Jira instance of system-wide changes with the new admin announcement banner

Hi All! We’re excited to share the launch of an announcement banner that lets Jira site administrators communicate directly to their users across their  Jira Cloud instance.  ...

688 views 17 19
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you