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,456,603
Community Members
 
Community Events
176
Community Groups

ScriptRunner "Add/Remove from Sprint" crashes with "Cannot invoke method left() on null object"

Edited

On Jira Server v8.0.2, using ScriptRunner 5.7.2-p5 I tried to use a built-in post function workflow script to add a ticket to active sprint, but it always fails with the following error

java.lang.NullPointerException: Cannot invoke method left() on null object
	at com.onresolve.scriptrunner.canned.jira.utils.agile.AddRemoveFromSprint.execute(AddRemoveFromSprint.groovy:260)
	at com.onresolve.scriptrunner.canned.jira.utils.agile.AddRemoveFromSprint$execute$2.call(Unknown Source)
	at com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.AddRemoveFromSprintProxy.execute(AddRemoveFromSprintProxy.groovy:79)
	at com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.AddRemoveFromSprintProxy$execute$1.callCurrent(Unknown Source)
	at com.onresolve.scriptrunner.canned.jira.workflow.AbstractWorkflowCannedScript.execute(AbstractWorkflowCannedScript.groovy:18)
	at com.onresolve.scriptrunner.canned.jira.workflow.AbstractWorkflowCannedScript$execute$0.call(Unknown Source)
	at com.onresolve.scriptrunner.jira.workflow.AbstractScriptWorkflowFunction$_run_closure1.doCall(AbstractScriptWorkflowFunction.groovy:93)
	at com.onresolve.scriptrunner.jira.workflow.AbstractScriptWorkflowFunction$_run_closure1.doCall(AbstractScriptWorkflowFunction.groovy)
	at com.onresolve.scriptrunner.runner.diag.DiagnosticsManagerImpl$DiagnosticsExecutionHandlerImpl.execute(DiagnosticsManagerImpl.groovy:314)
	at com.onresolve.scriptrunner.runner.diag.DiagnosticsExecutionHandler$execute$3.call(Unknown Source)
	at com.onresolve.scriptrunner.jira.workflow.AbstractScriptWorkflowFunction.run(AbstractScriptWorkflowFunction.groovy:86)

 I'm new to ScriptRunner and I wonder is there any way to see what AddRemoveFromSprint.groovy looks like?

So far following another example which uses `left` method as well, so I assume it has something in common with AddRemoveFromSprint script:

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.greenhopper.service.rapid.view.RapidViewService;
import com.atlassian.greenhopper.service.rapid.RapidViewQueryService;
import com.atlassian.greenhopper.model.rapid.RapidView;

import com.atlassian.greenhopper.service.sprint.Sprint;
import com.atlassian.greenhopper.service.sprint.SprintManager;

def sprintManager = ComponentAccessor.getOSGiComponentInstanceOfType(SprintManager.class);
def rapidViewService = ComponentAccessor.getOSGiComponentInstanceOfType(RapidViewService.class);
def rapidViewQueryService = ComponentAccessor.getOSGiComponentInstanceOfType(RapidViewQueryService.class);

def board_id = 10L;

def sprints = [];
def sprints_two = [];

import com.atlassian.jira.component.ComponentAccessor

def userManager = ComponentAccessor.getUserManager()

def user = userManager.getUserByKey("user.name")

def view = rapidViewService.getRapidView(user, board_id).getValue();

if (view != null)
{
sprints = rapidViewQueryService.getOpenSprintsAndBacklogProjects(user, view).getValue().left();
}

 I have confirmed that board_id is correct and matches the one I tried to use in the built-in script as well and above code returns correct sprint.

 

I will really appreciate any help as well as guidance is it possible to check built-in scripts code somewhere.

1 answer

1 accepted

0 votes
Answer accepted

I ended up using Custom post-function script:

import com.atlassian.greenhopper.service.rapid.view.RapidViewService
import com.atlassian.greenhopper.service.sprint.Sprint
import com.atlassian.greenhopper.service.sprint.SprintIssueService
import com.atlassian.greenhopper.service.sprint.SprintManager
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.runner.customisers.JiraAgileBean
import com.onresolve.scriptrunner.runner.customisers.WithPlugin

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

@JiraAgileBean
RapidViewService rapidViewService

@JiraAgileBean
SprintIssueService sprintIssueService

@JiraAgileBean
SprintManager sprintManager

// Enter the name of the board to which you want to add the issue to the first active sprint
def rapidBoardId = 8L

def loggedInUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def view = rapidViewService.getRapidView( loggedInUser, rapidBoardId ).getValue()

if( !view )
{
log.warn( "No view with this ID found" )
return
}

def sprints = sprintManager.getSprintsForView( view ).getValue()

def activeSprints = sprints
.findAll { it.active }
.sort { sprint_1, sprint_2 ->
sprint_1.getStartDate().isAfter( sprint_2.getStartDate() ) ? -1 : 1
} ?: new ArrayList<Sprint>()

if( activeSprints.size() > 0 )
{
def sprint = activeSprints[0]
log.info "Adding issue $issue to ${sprint.name}"
sprintIssueService.moveIssuesToSprint( loggedInUser, sprint, [issue] as Collection )
}
else
{
log.info( "No active sprints were found for board: ${view.name}" )
}

 Full credit should go to @Alexey Matveev _Appfire_ - I have copied and modified his script he posted here

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events