ScriptRunner script for delivery precision

I have a need for a script that can return the difference in dates between the date an issue was due and the date it was resolved (the idea is to provide a measurement for delivery precision).

I have tried something like this:

def dueDate = issue.getDueDate();
def resolutionDate = issue.getResolutionDate();
if (resolutionDate == null) {
return null;
}
return resolutionDate - dueDate;

The problem is that the (resolutionDate == null) gives an error since there apparently is a problem with the equals operator and the ingoing types of operands.

Yet, the code shows what I am trying to accomplish and I have tried different implementations but they all tend to generate a nullPointerException. The problem is that this is all there is in the log or the preview so I am stumbling in the dark.

Please, does anyone know how to accomplish this?

3 answers

1 accepted

Probably duedate is empty then, so lets check both due date and resolution date for null.

This works for me:

def dueDate = issue.getDueDate();

def resolutionDate = issue.getResolutionDate();
if (resolutionDate && dueDate) {
return resolutionDate - dueDate;

}

 

This did the trick; thank you!

Have you tried this?

def dueDate = issue.getDueDate();
def resolutionDate = issue.getResolutionDate();
if (resolutionDate) {
    return resolutionDate - dueDate;
}
 

I tried this but I get java.lang.NullPointerException: Cannot invoke method minus() on null object

Hi Karl,

The solution provided above by Filip is what you need to use ensuring you run this code as a scripted field on the issue.

I have attached a sample of how you can set this code as a scripted field in order to achieve your requirements.

Screen Shot 2016-08-19 at 16.05.05.png

I hope this helps.

Thanks

Kristian

Hi Karl!

Also there is a free of charge plugin - JIRA Misc Custom Fields

which allow to set calculated date fields. I have not tried it for now, but maybe it can help.

Regards
Vyacheslav

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published yesterday in Jira

5 ways you can make the most of Jira Software and Bitbucket Cloud

As part of the Bitbucket product team I'm always interested in better understanding what kind of impact the use of our tools have on the way you work. In a recent study we conducted of software devel...

58 views 0 5
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you