Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

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 Edited

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 com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.transform.BaseScript
import java.util.ArrayList;
import java.util.Collection;

@WithPlugin("com.pyxis.greenhopper.jira")

@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);
}
}

}
 

Error:

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: com.atlassian.greenhopper.api.events.sprint.SprintClosedEvent, 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)
at Script13.run(Script13.groovy:62)

 

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
TAGS
Community showcase
Published in Marketplace Apps & Integrations

Staying organized with Jira: best practices for a better project management

Project managers know this problem: A “mountain of work” lays in front of you, and you don’t know how and where to tackle them. Different to-dos lie ahead, but just one task after the other can be ha...

232 views 2 1
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