Obtain last sprint name for a story

Dave Cuff March 22, 2023

Hi gurus,

I am trying to loop through all stories linked to a epic to obtain the story and sprint name that is to be done last to update the EPIC with this sprint name.

I am able to use JQL query to get the stories however I don't seem to be able to see a way to obtain the sprint name from the sprint field returned.

This is the code relevant code from the script -
final customFieldName6 = "Sprint"
def customField6 = ComponentAccessor.customFieldManager.customFieldObjects.findByName(customFieldName6)
assert customField6 : "Could not find custom field with name ${customFieldName6}"
def cfSprint = issue3.getCustomFieldValue(customField6).
This is value returned in cfSprint - "[com.atlassian.greenhopper.service.sprint.Sprint@5922bda1[id=2774,rapidViewId=734,state=CLOSED,name=DC PI14 - S1 - SXBC,startDate=2023-02-13T00:00:00.000Z,endDate=2023-02-26T00:00:00.000Z,completeDate=2023-02-25T06:29:50.993Z,activatedDate=2023-02-13T06:21:02.220Z,sequence=2774,goal=,autoStartStop=false], com.atlassian.greenhopper.service.sprint.Sprint@78ea9d6d[id=2786,rapidViewId=734,state=FUTURE,name=DC PI14 - S3 - SXBC,startDate=2023-03-13T00:00:00.000Z,endDate=2023-03-26T00:00:00.000Z,completeDate=<null>,activatedDate=<null>,sequence=2786,goal=<null>,autoStartStop=false]] 2023-03-23 05:14:41,505 WARN [acme.workflows]: End

I need now to interrogate this string to obtain the last name in the string.  NB - there are often multiple names in the string.

Please help suggest how I do this.

Dave

  

1 answer

0 votes
Ram Kumar Aravindakshan _Adaptavist_
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 24, 2023

Hi @Dave Cuff

For your requirement, I suggest using the ScriptRunner console.

Below is a sample working code for your reference:-

import com.adaptavist.hapi.jira.issues.Issues

def epic = Issues.getByKey('MOCK-2')
def links = epic.getOutwardLinks { excludeSystemLinks = false }

links.each {
def issue = it.destinationObject
def sprint = issue.getCustomFieldValue('Sprint')['name'] as List
if (sprint.size() > 0) {
log.warn "=====>>> Isuse Key: ${issue.key}, Last Sprint Name: ${sprint.last()}"
}
}

Please note that the sample code above is not 100% exact to your environment. Hence, you will need to make the required modifications.

Please note that the sample code has been coded using ScriptRunner's HAPI feature. I suggest upgrading your ScriptRunner plugin to the latest release, i.e. 7.13.0 and using the HAPI feature to simplify the coding.

Below is a screenshot of the output returned:-

image1.png

Below is a screenshot of the sample sprints I am testing with:-

image2.png

I hope this helps to answer your question. :-)

Thank you and Kind regards,

Ram

Dave Cuff March 29, 2023

Thank you for this.  

We don't have hapi yet. "I am not happy"

Any suggestions if you don't have HAPI.

 

Dave

Ram Kumar Aravindakshan _Adaptavist_
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, 2023

Hi @Dave Cuff

If you are not using HAPI, you will need to invoke the ComponentAccessor to access the IssueManager, and via the IssueManager, invoke the issue.

So there are a lot more steps, as shown below:-

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue

def issueManager = ComponentAccessor.issueManager
def epic = issueManager.getIssueByCurrentKey('MOCK-2')
def links = epic.getOutwardLinks(epic.id)

links.each {
def issue = it.destinationObject
def sprint = issue.getCustomFieldValue('Sprint')['name'] as List
if (sprint.size() > 0) {
log.warn "=====>>> Isuse Key: ${issue.key}, Last Sprint Name: ${sprint.last()}"
}
}


Please note that the sample code above is not 100% exact to your environment. Hence, you will need to make the required modifications.

I hope this helps to answer your question. :-)

Thank you and Kind regards,

Ram

Dave Cuff March 30, 2023

Thank you fo this.

Let me try and get this working in a listener script.

Dave


Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
8.20.12
TAGS
AUG Leaders

Atlassian Community Events