Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How can I get the OPEN / FUTURE sprint name from an issue using REST API?

alexmears
Contributor
August 27, 2018

Goal: I am trying to get the Sprint Name the OPEN / FUTURE sprint value for an issue.

I currently have the following script using ActivistScriptRunner listener.

def customFields = get("/rest/api/2/field")
.asObject(List)
.body
.findAll { (it as Map).custom } as List<Map>

def inputid = customFields.find { it.name == 'Sprint' }?.id
def sprints = issue.fields[inputid];

 The problem is this returns the sprints associated with an issue as follows:

[com.atlassian.greenhopper.service.sprint.Sprint@68451349[id=3,rapidViewId=1,state=CLOSED,name=180819,goal=,startDate=2018-08-11T22:00:07.984Z,endDate=2018-08-18T22:00:00.000Z,completeDate=2018-08-19T23:55:04.664Z,sequence=3], com.atlassian.greenhopper.service.sprint.Sprint@4685dba[id=4,rapidViewId=1,state=FUTURE,name=180916,goal=,startDate=<null>,endDate=<null>,completeDate=<null>,sequence=7], com.atlassian.greenhopper.service.sprint.Sprint@24ed7d97[id=8,rapidViewId=1,state=CLOSED,name=180826,goal=,startDate=2018-08-19T13:59:07.365Z,endDate=2018-08-26T13:59:00.000Z,completeDate=2018-08-26T22:39:33.453Z,sequence=4]]  

And I don't know how to extract sprint name for the OPEN / FUTURE sprint from this result.

Question:

  1. Is there an easier way to do this than I am pursuing? e.g. a single REST API get method that sends back the OPEN / FUTURE sprint name, or
  2. Is there a way to extract the sprint name for the OPEN / FUTURE sprint from "sprints". I have tried "Get" but apparently it is not a support method, since "sprints" is an object and not an array or list.

 

2 answers

1 accepted

0 votes
Answer accepted
alexmears
Contributor
August 29, 2018

The solution was very simple, after mapping issue's fields with:

def fields = issue.fields as Map

you can then get the sprint name:

def sprintName = fields.sprint.name

The reason this didn't seem to work is because the script runner listener console was incorrectly flagging "def sprintName = fields.sprint.name" with an error. The script still works.

kieran O Mahony
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 14, 2020

,

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.
August 27, 2018
alexmears
Contributor
August 27, 2018

@Alexey Matveev, I have gone through that page. It didn't cover Sprints as a field, which can have multiple values and states. I have tried a few guesses at how Sprints would work, but have had no luck.

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.
August 27, 2018

As far as I understand this Api call returns you this data:

 "sprint": {
      "id": 37,
      "self": "http://www.example.com/jira/rest/agile/1.0/sprint/13",
      "state": "future",
      "name": "sprint 2",
      "goal": "sprint 2 goal"
    },
    "closedSprints": [
      {
        "id": 37,
        "self": "http://www.example.com/jira/rest/agile/1.0/sprint/23",
        "state": "closed",
        "name": "sprint 1",
        "startDate": "2015-04-11T15:22:00.000+10:00",
        "endDate": "2015-04-20T01:22:00.000+10:00",
        "completeDate": "2015-04-20T11:04:00.000+10:00",
        "goal": "sprint 1 goal"
      }
    ],

What else do you need?

alexmears
Contributor
August 29, 2018

Thank you for your help. The solution was actually very simple. I have added it below.

Suggest an answer

Log in or Sign up to answer