It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Create Calculated or Scripted Field to Return "Closed in Sprint" value

Hi,

 

I have JIRA Misc Custom Fields 2.0 and Script Runner installed on JIRA Server.  

 

Am looking for a way to put the sprint a ticket was resolved in into a calculated field.

Lots of Google searches later, I'm still not sure if anyone else has been able to do this.

Looking at the info available, it seems it should definitely be possible, but perhaps not very simple!

 

Any pointers welcome... Thanks!

2 answers

0 votes
Antoine Berry Community Leader Jun 03, 2019

Hi @Matt ,

With ScriptRunner my best guess would be to use a Script Listener on the Resolve Issue event, retrieve the sprint name and store it in a text field.

Unfortunately to my knowledge a sprint custom field does not exist, and JMCF does not seem to provide it either (looking at the doc). This means the name will not be updated if the sprint name is updated.

Antoine

0 votes

Hi Matt,

I guess it would depend on how you define "the sprint a ticket was resolved in".

If you want to capture the current sprint the issue belongs to when the "Resolve" transition is run, then you can use a post-function such as JMWE's Set Field Value post-function to store the current sprint into a custom text field.

Otherwise, you could create a calculated custom field that returns the "latest" sprint the issue belonged to, but that's not exactly the same thing.

So it depends on what information you really want to display.

Hi All, thanks to both of you who replied.  If anyone is interested then I ended up writing a calculated field script to return the sprint number that an issue was resolved in from the sprint title.  Works pretty well with only a few edge cases that I can override manually.  Edge cases include when a ticket was re-opened after it was originally closed, or if you have a "Done" status type that isn't in the final column of your sprint.

import java.sql.Timestamp

//This is the script for Resolving Sprint (Automated)


//Determining how to Read the lastSprint value. Returns the third word in the sprint name (in this case it would be "S78" for example)

def getSprint(name) {
sprintNameSplit = name.split(" ")
return sprintNameSplit[2]
}
sprintOverride = issue.get("customfield_13911") //Issue field ID for Resolving Sprint Override


//Finds the resolutionDate for the issue

if (!(sprintOverride== null) ){
return sprintOverride
}else{
resolutionDate = issue.resolutionDate // returns this value 2019-05-02 12:03:35.811 for 11208

if (!resolutionDate) return "Not Yet Resolved"


//Returns an empty value if a ticket was resolved outside of a Sprint (e.g. in the backlog)

if (issue.get("customfield_10000").equals(null)) {
return null
}


//Looking for the last sprint

lastSprint = issue.get("customfield_10000").last()


// If Sprint has not started then return No Resolving Sprint

String lastSprintState = lastSprint.state
if (lastSprintState.equals("FUTURE")){
return "No Resolving Sprint"
}

//Tales the last Sprint and gets the Sprint Start Date
sprintStart = new Timestamp(lastSprint.startDate.getMillis())


//Takes the last Sprint and gets the completeDate if available, else it gets the endDate

sprintComplete = lastSprint.completeDate ? new Timestamp(lastSprint.completeDate.getMillis()) : new Timestamp(lastSprint.endDate.getMillis())


//Checks if Resolution Date is Within Window of Last Sprint if so it returns the sprint value, else it returns an error message. When error message shows, an override can be added using customfield_13911

if (resolutionDate.after(sprintStart) && resolutionDate.before(sprintComplete)) {
return getSprint(lastSprint.name)
} else {
return "Resolution Date Mismatch"
}
}

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you