Set default value of Sprint Field

Yuval Maron May 10, 2021

Hey,

I'll be happy to know if there is any way to set by default the Sprint field value to be the same as the current active sprint. 

I'm using ScriptRunner, Thanks in advance!

1 answer

0 votes
John Chin
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 10, 2021

Hi @Yuval Maron 

Yes, it is doable. You can put the following script in the Initialiser field:

package examples.docs

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

/**
* Configurable section
*/
// Enter the board id to which you want to add the issue to the first active sprint
def rapidBoardId = 1L

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

@JiraAgileBean
RapidViewService rapidViewService

@JiraAgileBean
SprintIssueService sprintIssueService

@JiraAgileBean
SprintManager sprintManager

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

// Sprint Field

def field = getFieldByName("Sprint")

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

// get all sprints in the Rapid Board

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

// find active sprint

def activeSprint = sprints.find { it.active }

if (activeSprint) {

// set Active Sprint ID

field.setFormValue(activeSprint.id)
}

The configuration should be looking like this:

Screenshot 2021-05-11 at 1.17.37 PM.png

Then, save the Behaviour config with the script. Next, go to the Create Issue screen and you will see the Sprint field has set to the default active sprint. 

A recorded demo for your reference - video.mp4

Bear in mind, the script is made for Behaviour. You can reuse the script for other such as post-function or listeners. If that the case, please remove this line:

def field = getFieldByName("Sprint")

field.setFormValue(activeSprint.id)

And, replace with other script to get the Sprint custom field name and set to the issue.

I hope this helps.

Yuval Maron May 12, 2021

Hey @John Chin ,

Thank you so much for this!

John Chin
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 16, 2021

Hi @Yuval Maron ,

No problem :)

Feel free to accept the answers if its working for you.

Suggest an answer

Log in or Sign up to answer