Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

ScriptRunner script for delivery precision

Karl-König Königsson August 19, 2016

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

2 votes
Answer accepted
Filip Håkansson
Contributor
August 19, 2016

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;

}

 

Karl-König Königsson August 21, 2016

This did the trick; thank you!

0 votes
TSD Group August 19, 2016

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

0 votes
Filip Håkansson
Contributor
August 19, 2016

Have you tried this?

def dueDate = issue.getDueDate();
def resolutionDate = issue.getResolutionDate();
if (resolutionDate) {
    return resolutionDate - dueDate;
}
 
Karl-König Königsson August 19, 2016

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

Kristian Walker _Adaptavist_
Community Champion
August 19, 2016

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

Suggest an answer

Log in or Sign up to answer