Forums

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

Trouble Calculating Number of Days Between Dates Using Jira Misc Custom Fields

Brian Baumgartner April 12, 2018

I've found several discussions on this topic, but can't seem to get any to work.  I have the below code implemented on my system and the 2 custom date fields are filled in, but my new field doesn't show up...

<!-- @@Formula:
if (issue.get("customfield_10779")==null || issue.get("customfield_10652") == null)
return null;
return (issue.get("customfield_10779").getTime() - issue.get("customfield_10652").getTime()) / 1000 / 3600 / 24; -->

Some additional details/questions:

  • JIRA Server 
  • Date Custom Fields are Date (not Date/Time)
  • Using Custom Calculated Number Field
  • Custom Calculated Number Field is added to project screen

Does the calculation happen automatically / on refresh?  Or does it require a transition to take place?

Is there a way to easily check what's going on under the hood to see what JIRA thinks the fields are set to so that I can try to understand why the calculation isn't working?

 

UPDATE: It loos like the formula wasn't working because the initial fields were 'date picker' type instead of 'date/time picker' type.  Is there any way to use just date?  I can't find a good list of possible commands anywhere...

1 answer

1 accepted

1 vote
Answer accepted
David Fischer
Community Champion
April 13, 2018

Hi Brian,

You need to create a custom calculated number field. 

As for the formula, it seems correct. 

To check for errors, look inside the Jira logfile (atlassian-jira.log). 

Brian Baumgartner April 13, 2018

I am using a calculated number field (updated original post).  This log is on server as well?

David Fischer
Community Champion
April 13, 2018

This log is only on server... It's the standard Jira Server logging system (on the Cloud, you don't have access to Jira logs).

Brian Baumgartner April 14, 2018

It loos like the formula wasn't working because the initial fields were 'date picker' type instead of 'date/time picker' type.  Is there any way to use just date?  I can't find a good list of possible commands anywhere...

David Fischer
Community Champion
April 14, 2018

Date picker fields are supported just as well as date/time picker fields. The problem must have been elsewhere. Did you find anything in the logs?

https://innovalog.atlassian.net/wiki/x/BYAbAg explains how to access issue fields from a formula. 

Brian Baumgartner April 14, 2018

Now that you mention it should work with date only (not date/time), I'm realizing that I also completely changed the fields (I think from custom to built in ones).  So...there is a bit here that still isn't working properly.

I didn't see anything interesting in the logs that I have access to.  I'm working with our IT guy to get access to the logs on the server (I used the system tools to see if anything was there that I could use...).

Brian Baumgartner April 14, 2018

Okay, it works now.  A couple of strange things happened, but I'm guessing the root cause is user error.  When I went to switch back to the original fields for the equation, the ID number for at least 1 of the 2 fields was different than previously (so either it changed, I was using a stale tab, or I just completely pulled the wrong tab...unless something was off/wrong with the server or indexing or something weird I don't understand.

Anyways, it works how it should now and I'm good to go.  Thanks for all your support.  Sorry if this was a wild goose chase.

David Fischer
Community Champion
April 14, 2018

Are you aware that you can also use field names instead of field IDs with issue.get? Of course, it'll break if you later rename the field, but for testing it can be faster. 

Brian Baumgartner April 16, 2018

I did not know that.  It might have made things go smoother...or at least helped with troubleshooting.  Thanks for the tip.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events