Add to current sprint

Ryan Fisher November 3, 2016

Is there any way to add an issue to the current sprint on transition? I want to auto add issues to the active sprint when devs (who forget to move their issue) transition it to in progress.

3 answers

0 votes
David _old account_
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.
November 4, 2016

This feature is not currently available in JMWE for JIRA Cloud, but I've created https://innovalog.atlassian.net/browse/MWEC-126 which you might want to vote for and watch. We might be able to release this feature later this month.

However, note that sprints belong to Boards, so you will have to specify a board ID (there is no way currently to identify which board(s) an issue belongs to).

Evgeny Erofeev November 23, 2017

So, how to add an issue to the current sprint? I can see that the suggestion is implemented. But I can't find this functionality in JMWE.

David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 23, 2017

The aforementioned ticket contains a code snippet that returns the current sprint ID. You can use the Set Field Value post function to set the Sprint field to that value. See https://innovalog.atlassian.net/wiki/spaces/JMWEC/pages/138405679/Custom+Nunjucks+filters#CustomNunjucksfilters-sprints and https://innovalog.atlassian.net/wiki/spaces/JMWEC/pages/94142534/Set+field+value

Evgeny Erofeev November 23, 2017

I tried it. A create such a Post Function for `Done`:

```

The value of field Sprint of the current issue will be set to the following Groovy Template: {{ issue | sprints("active") | first | field("id") }} (replacing existing values).

```

It doesn't do anything though. I don't understand what's wrong :(

Evgeny Erofeev November 23, 2017

Hmm, I'm afraid, Nunjucks is not supported by JMWE for JIRA Server...

David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 23, 2017

That's true. But the same can be achieved using Groovy - we'll provide the script later today.

Evgeny Erofeev November 23, 2017

Thanks a lot! I’m looking forward. It’ll help me so much.

Evgeny Erofeev November 26, 2017

So, there is no way to get current sprint using groovy, I suppose...

David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 27, 2017

Actually, there is, but Jira Software doesn't make it easy.

The following script should work to return the Sprint ID (number), but you'll have to customize it with the numerical ID of the Scrum board (because there is no direct relationship between issues and Scrum boards - an issue can even belong to multiple boards). That number is the "rapidView=" parameter of your board's URL.

import com.atlassian.jira.component.ComponentAccessor

def boardId = 2

def classLoader = issue.get("Rank").getClass().getClassLoader()

def RapidViewServiceIntf = classLoader.findClass("com.atlassian.greenhopper.service.rapid.view.RapidViewService")
def RapidViewService = ComponentAccessor.getOSGiComponentInstanceOfType(RapidViewServiceIntf)

def board = RapidViewService.getRapidView(currentUser, boardId).get()

def SprintServiceIntf = classLoader.findClass("com.atlassian.greenhopper.service.sprint.SprintService")
def SprintService = ComponentAccessor.getOSGiComponentInstanceOfType(SprintServiceIntf)

def PageRequests = classLoader.findClass("com.atlassian.greenhopper.service.PageRequests")
def SprintQuery = classLoader.findClass("com.atlassian.greenhopper.service.sprint.SprintQuery")
def State = classLoader.findClass("com.atlassian.greenhopper.service.sprint.Sprint").getClasses()[1]

def sprintQuery = SprintQuery.builder().states(Collections.singleton(State.ACTIVE)).build()
def sprintsOutcome = SprintService.getSprints(currentUser, board, PageRequests.all(), sprintQuery)
if (sprintsOutcome.isInvalid())
throw new UnsupportedOperationException(sprintsOutcome.toString())
def sprints = sprintsOutcome.get().getValues()

if (sprints.size() > 1)
throw new UnsupportedOperationException("More than one sprint is active")
return sprints[0].getId()

We'll try to make it easier in a future version of JMWE for Jira Server.

David

Max Nikolsky March 14, 2018

Hi David!

I've tried to use this script as a postfunction. My aim is to fill current active sprint by default for new tasks. I've choosen "Create issue" on workdlow diagram, added new postfunction. I use "Set filed value (JMWE)" option. As an affected field I've set "Sprint", as value type - Groovy Expression.

When I try to test you script, I have an error:

java.lang.IllegalArgumentException: Unable to find field 'Rank'

And this postfunction does not allow to create new tasks at all.

So, can I do something to resolve this?

P.S: Jira Server 7.8.0, JMWE 5.2.0

Max Nikolsky March 14, 2018

Hi David!

I've tried to use this script as a postfunction. My aim is to fill current active sprint by default for new tasks. I've choosen "Create issue" on workdlow diagram, added new postfunction. I use "Set filed value (JMWE)" option. As an affected field I've set "Sprint", as value type - Groovy Expression.

When I try to test your script, I have an error:

java.lang.IllegalArgumentException: Unable to find field 'Rank'

And this postfunction does not allow to create new tasks at all.

So, can I do something to resolve this?

P.S: Jira Server 7.8.0, JMWE 5.2.0

Max Nikolsky March 14, 2018

Hi David!

I've tried to use this script as a postfunction. My aim is to fill current active sprint by default for new tasks. I've choosen "Create issue" on workdlow diagram, added new postfunction. I use "Set filed value (JMWE)" option. As an affected field I've set "Sprint", as value type - Groovy Expression.

When I try to test this script, I have an error:

java.lang.IllegalArgumentException: Unable to find field 'Rank'

And this postfunction does not allow to create new tasks at all.

So, can I do something to resolve this?

P.S: Jira Server 7.8.0, JMWE 5.2.0

David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 14, 2018

Hi Max,

please refer to https://innovalog.atlassian.net/wiki/x/oIC8CQ for an updated version of this script.

Max Nikolsky March 18, 2018

Thank you! Works excelent for me!

Can this script also run in Jira Server 7.6.2?

P.S: wiki link for me was https://innovalog.atlassian.net/wiki/spaces/JMWE/pages/68878646/Use+cases+for+post+functions#Usecasesforpostfunctions-AddtheissuetothecurrentactiveSprint

David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 19, 2018

Yes, this script will work with any 7.x version of Jira, but it requires JMWE version 5.1.0 or above.

Stef Klaassen March 23, 2018

Hi @David Fischer 

You're first script seems to work for me when I try it using the "Test Groovy Script" button. However after I've added this to the post-function of the workflow transition (on creation of the issue) the Sprint value never gets filled in. Any ideas why this could be? 

We're on Jira 7.6.3 and JMWE version 5.0.6. 

David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 23, 2018

No idea. Did you look at the Jira logs (atlassian-jira.log)? Did you try the post-function on a "normal" transition?

Stef Klaassen March 23, 2018

Thanks for your quick reply. I was going through some documentation of JMWE and found another troubleshooting article on a create transition and figured out the solution was to put the post-function after all the other (default) post-functions. 

ldogangul March 29, 2018
David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 29, 2018

The link doesn’t work...

ldogangul March 29, 2018

Hi David,

It's strange. I cannot add the correct link. Can you please find the topic under my profile ?

How can I set value 0 if a transitioon count field is empty ?

Thanks..

0 votes
Ryan Fisher November 4, 2016

Cloud

0 votes
David _old account_
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.
November 4, 2016

On JIRA Server or JIRA Cloud?

Suggest an answer

Log in or Sign up to answer