Groovy Script to get Sprint start Date for ACTIVE State sprint

Juan Martinez May 5, 2022

I want to build a custom scripted field that for a given Issue will return the sprint start date BUT only for the active sprint.

In reading the value of the 'Sprint' field I can see the sequence of my sprints is a bit tricky so I cant just use ".first" or ".last" to pull the date i need so i thought I could use the state field to help me select the sprint I need then pull the date from there. I tried
using this modified script but I can't get it to work. Any help would be much appreciated.

 

Script I'm using:


import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.issue.link.IssueLinkType
import com.atlassian.jira.issue.link.IssueLinkTypeManager
import java.util.concurrent.TimeUnit
import com.atlassian.jira.issue.CustomFieldManager

def cfManager = ComponentAccessor.getCustomFieldManager()
def issue = issue
def customFieldManager = ComponentAccessor.getCustomFieldManager();
def sprintField = customFieldManager.getCustomFieldObjectByName("Sprint");
def sprints = issue.getCustomFieldValue(sprintField)
def Activesprintstartdate=sprints.state.ACTIVE.startDate?.toDate()

log.warn(Activesprintstartdate)

return Activesprintstartdate


As an example of what I've got for an Issue that appears in more than two sprints ..the bolded underlined date is the one i need. 

2022-05-05 19:04:09,788 WARN [runner.ScriptBindingsManager]: GCP-29181 [com.atlassian.greenhopper.service.sprint.Sprint@40901b8e[id=453,rapidViewId=90,state=CLOSED,name=Sprint 2206,startDate=2022-03-29T21:42:00.000-04:00,endDate=2022-04-12T21:42:00.000-04:00,completeDate=2022-04-12T20:42:35.084-04:00,activatedDate=2022-03-29T21:42:42.195-04:00,sequence=457,goal=,autoStartStop=false], com.atlassian.greenhopper.service.sprint.Sprint@5fd06f96[id=454,rapidViewId=90,state=CLOSED,name=Sprint 2207,startDate=2022-04-12T20:43:00.000-04:00,endDate=2022-04-26T20:43:00.000-04:00,completeDate=2022-04-26T23:44:46.993-04:00,activatedDate=2022-04-12T20:43:07.740-04:00,sequence=463,goal=,autoStartStop=false], com.atlassian.greenhopper.service.sprint.Sprint@65375fe9[id=455,rapidViewId=90,state=ACTIVE,name=Sprint 2208,startDate=2022-04-26T23:45:00.000-04:00,endDate=2022-05-10T23:45:00.000-04:00,completeDate=<null>,activatedDate=2022-04-26T23:45:36.525-04:00,sequence=466,goal=,autoStartStop=false], com.atlassian.greenhopper.service.sprint.Sprint@554fd4d5[id=456,rapidViewId=90,state=CLOSED,name=Sprint 2205,startDate=2022-03-15T23:27:00.000-04:00,endDate=2022-03-29T23:27:00.000-04:00,completeDate=2022-03-29T21:42:05.684-04:00,activatedDate=2022-03-15T23:27:46.895-04:00,sequence=456,goal=,autoStartStop=false]]

1 answer

0 votes
Jerel Crosland October 27, 2022

Hello @Juan Martinez ! Did you ever figure this out? I have the same requirement.

Juan Martinez October 28, 2022

Hi @Jerel Crosland  unfortunately I did not :( 

Suggest an answer

Log in or Sign up to answer