You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
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)
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 ....
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.