Trying to get Resolution Time

Marc Jason Mutuc
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.
June 7, 2014

I'm trying to get the resolution time since the SLA in Service Desk is using + / - in the time. I just need the number of days spend on a ticket. I used the following formulas. but it did not give me any result. Am I missing anything?

<!-- @@Formula: issue.get("resolved")==null ? null : (issue.get("resolved").getTime() - issue.get("created").getTime()) / 1000 / 3600 / 24 -->

<!-- @@Formula: issue.get("resolutiondate")==null ? null : (issue.get("resolutiondate").getTime() - issue.get("created").getTime()) / 1000 / 3600 / 24 -->

6 answers

1 accepted

1 vote
Answer accepted
David _old account_
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.
June 8, 2014

That's because you created a Calculated Date/Time field when what you want to return is a Number (of days). So you need to create a Calculated Number Field instead.

Marc Jason Mutuc
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.
June 8, 2014

Thanks David! It works now! I should've thought of that.

I've another field using your add-on. It's working but it throws the following error on my logs.

CalculatedDateField: error evaluating formula: Sourced file: inline evaluation of: `` org.apache.commons.lang.time.DateUtils.addDays(issue.get("customfield_13702"),1 . . . '' : Method Invocation org.apache.commons.lang.time.DateUtils.addDays

Here is the code I'm using.

<!-- @@Formula: org.apache.commons.lang.time.DateUtils.addDays(issue.get("customfield_13702"),30) -->

David _old account_
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.
June 8, 2014

You're welcome.

As for your other problem, can you post the entire error? There must be another line following this one.

Can you possibly try the following SNAPSHOT release and tell me if it fixes your issue? https://innovalog.atlassian.net/secure/attachment/25267/jira-misc-custom-fields-1.5.9-SNAPSHOT.jar

Marc Jason Mutuc
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.
June 9, 2014

Thanks David! I'm currently testing them. So far, you really need to reindex when you add a calculated field. If you don't it would still show the error.

Here are the steps I did.

1. Upload Add-On

2. Background Reindex

3. Created Custom Field

4. Background Reindex

While the Reindex is not yet finished, the logs are being filled with the

[innovalog.jmcf.fields.CalculatedDateField] CalculatedDateField: error evaluating formula: Sourced file: inline evaluation of: `` org.apache.commons.lang.time.DateUtils.addDays(issue.get("customfield_13702"),1 . . . '' : Method Invocation org.apache.commons.lang.time.DateUtils.addDays

After reindex, no sign of the error message. I haven't tried locked reindex but I would assume that the error messages would not be thrown.

David _old account_
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.
June 9, 2014

When you reindex, it will compute the field for all issues. So I suspect it's because some issues have a null value in field customfield_13702

You need to protect against null values in your formula:

if (issue.get("customfield_13702")==null) return null;


Marc Jason Mutuc
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.
June 9, 2014

Awesome! Works perfectly now! Thanks a lot David!

0 votes
Geoff Rich December 9, 2014

Thanks a lot! That seems to work great.

0 votes
David _old account_
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.
December 9, 2014
&lt;!-- @@Formula: issue.get("resolutiondate")==null ? null : ((Double)(issue.get("resolutiondate").getTime() - issue.get("created").getTime())) / 1000 / 3600 / 24 --&gt;
0 votes
Geoff Rich December 9, 2014

David,

The second formula above works for me, as I am calculating the total time between a ticket Created and Resolved. However, it looks like it gets returned as an integer. Is there any any way to return as a decimal (for example, a ticket under 24 hours is all getting returned as "0" )

 

Thanks,
Geoff 

0 votes
David _old account_
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.
June 8, 2014

The correct formula is the second one.

To verify the syntax of your formula, you can look into your log gile (atlassian-jira.log) for errors.

To verify that the formula is entered in the appropriate location, replace is with: @@Formula: 1 and make sure that your field then displays "1".

Also make sure the Resolution Date field is correctly set on your JIRA issue.

Make sure the custom field is added to the View ISsue screen, and then look at the field value in the issue screen (the issue navigator is based on the Index, which will need to be rebuilt once your formula works).

0 votes
Marc Jason Mutuc
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.
June 8, 2014

Error seen on logs are CalculatedDateField: formula does did return a Date object:

Suggest an answer

Log in or Sign up to answer