Programatically Update the Sprint Field in Issues

Joe Zangara February 7, 2018

Hi All, 

I have a list of closed issues where users forgot to set the sprint fielld.

Each issue in the list belongs to a different sprint.

Those Sprints are also closed.

I fixed the problem going forward by imposing a required field validator on Sprint in a workflow transition.  Now I just need to fix the old data.

The only way I know of to make this update is to use bulk edit one-by-one for each issue and set the Sprint field to equal the Sprint ID.

 

I was hoping that this could be done programatically.

Any guidance would be greatly appreciated.

2 answers

0 votes
Alexey Matveev
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.
February 7, 2018

You can do it programatically. What add-on do you have? Power Scripts or ScriptRunner?

Joe Zangara February 7, 2018

I have Script Runner.  Not very experienced in using it though.

 

I have a list of IssueIDs and the SprintIDs. they need to be updated with.

Alexey Matveev
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.
February 7, 2018
Alexey Matveev
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.
February 7, 2018

This script worked for me

import com.atlassian.greenhopper.service.sprint.SprintManager
import com.onresolve.scriptrunner.runner.customisers.PluginModuleCompilationCustomiser
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption

@WithPlugin("com.pyxis.greenhopper.jira")
def sprintManager = PluginModuleCompilationCustomiser.getGreenHopperBean(SprintManager)

def sprintServiceOutcome = sprintManager.getAllSprints()
def issue = ComponentAccessor.getIssueManager().getIssueByCurrentKey("MAV-1")

if (sprintServiceOutcome?.valid) {
def sprint = sprintServiceOutcome.getValue().find {it.name == "Sprint 1"}
if (!sprint) {
log.debug "Could not find sprint with name <SPrint 1>"
} else {
log.error(sprint)
issue.setCustomFieldValue(
ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Sprint")
, Arrays.asList(sprint))

ComponentAccessor.getIssueManager().updateIssue(ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
, issue
, EventDispatchOption.ISSUE_UPDATED
, false)
}
}
Harish_Kumar April 18, 2020

Hi @Alexey Matveev , can you please help me on . When a user clicks on sprint complete button . In the back end a field Goal is set to some text data programmatically . Can you help me on this thanks. Harish

0 votes
Fabrizio Galletti
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.
February 7, 2018

You can try to build a custom script to change this 

You can execute it in built in scripts (script runner) or add it as workflow post function and execute as a bulk action on closed issues

Suggest an answer

Log in or Sign up to answer