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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,560,309
Community Members
 
Community Events
185
Community Groups

Groovy Script Cast Exception

Edited
Yogesh Mude
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Apr 30, 2019

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
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
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);

Marc Minten _EVS_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 06, 2019

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

Atlassian Community Events