JIRA Agile sprint start date and end date custom field

Mehmet Kazgan
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 11, 2014

I am trying to add sprint end date and start date custom fields. I though I could do that by:

1. Adding a groovy scripted field and update it from the database during workflow transition

2. Database values plugin

Any ideas?

2 answers

1 accepted

4 votes
Answer accepted
JamieA
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 18, 2014

I don't see a problem having a scripted field. Here's code that works for me.

Use the "date time range indexer", and the "date" template:

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

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def sprintCf = customFieldManager.getCustomFieldObjectByName("Sprint")
Issue issue = issue
issue.getCustomFieldValue(sprintCf)?.startDate?.first()?.toDate()

Mehmet Kazgan
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 18, 2014

Thanks Jamie, this is brilliant.

G November 7, 2016

Jira 7.2 doesn't seem to like the start date - no such property: startDate for class: java.lang.Object. Do you have an updated code?

G November 7, 2016

Okay this works now for JIRA 7 if I use getCustomFieldObject and use the ID instead of name. 

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def sprintCf = customFieldManager.getCustomFieldObject(10004)
Issue issue = issue
issue.getCustomFieldValue(sprintCf)?.startDate?.first()?.toDate()

 

JamieA
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 9, 2016

The problem is just that getCustomFieldValue is declared as returning Object - see https://scriptrunner.adaptavist.com/latest/jira/#_providing_type_information

Jamie Cole December 23, 2016

Hi Jamie, could you explain this I'm not a coder and would like to use script, I have tried this in ira 6.4.4 and 7.1.9 with the same result.

JamieA
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.
January 2, 2017

What's the result you're getting? I'm not sure what you need help with to be honest.

Antônio Duarte July 6, 2017

Hi, Jamie: 

I'm a newbie on scripts, but your script doesn't work for me, also.

I get this error shown in the image.

Can you help, please?

Thanks.

Antonio.atlassian1.jpgAtlassian2.jpg

JamieA
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.
July 9, 2017

That is safe to ignore - it's just that we can't calculate what type of field is returned by getting the Sprint custom field value. We are working on something better.

Antônio Duarte July 10, 2017

Thanks, Jamie. So, waiting for news from Adaptavist.

Do you have an idea on when will this be available?

Greetings.

 

JamieA
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.
July 10, 2017

I think you misunderstand me. The script should work right now. The type checking errors you can just ignore, or cast to the correct type, but that's more complex.

https://scriptrunner.adaptavist.com/latest/jira/#_static_type_checking

Antônio Duarte July 10, 2017

It is clear, now, Jamie.

Thank you very much!

Julien Guilbert March 15, 2019

Hi

Is it possible to do the same with a "IF" to return the information of the  "Active sprint" ?

Because currently the field returns to me the date of the first sprint in which my ticket was assigned.

Thanks

1 vote
Alexey_Rjeutski__Polontech_
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 11, 2014

1. If you are updating the field during transition - you don't need the scripted field - it would be ok to have readonly field

2. Please also think about development of your plugin with calculated field - as for me it can be easier maintained during upgrade routines.

https://developer.atlassian.com/display/JIRADEV/Creating+a+Custom+Field+Type

https://docs.atlassian.com/jira/latest/com/atlassian/jira/issue/customfields/impl/CalculatedCFType.html

Suggest an answer

Log in or Sign up to answer