Jira Misc Custom Fields calculated date (add days)

Hello,

 

I have installed the Misc Custom Fields add-on for Jira, but need some guidance on the correct formula to use to produce a date that is X days after another date field.

 

For example, if an email was sent on 1/1/17, the response would be due 14 days later, and I would want the calculated field to show 1/15/17.

 

Any suggestions?

 

Thanks,

 

Shanelle

4 answers

I need some assistance with this too, did you find a solution by any chance?

Nothing with this add-on.  I did see that the (paid) Jira Workflow Toolbox add-on appears to have this functionality (on a transition), but I haven't had a chance to test.

 

https://bitbucket.org/fcarmario/jira-workflow-toolbox/wiki/others/Examples%20of%20Math-Time%20expressions

There seems to be another which seemed to work for me. 

 

Get this add on: Jira Misc Workflow Extensions

And then on post functions you can do update field and select the custom date field you have created in this scenario "Lead time target date" and write the below

Lead time target date: {{ now | date('add', 14, 'days') | 'date') | date }}

 

This should populate the field but it is based on created date of the issue. 

Hi Kirti,

the syntax you provided is for Jira Cloud. On Jira Server, the syntax would be different:

new Date() + 14

As for JMCF, this is how you would do it. Imagine the field that holds the email date is called "Sent On":

if (issue.get("Sent On") == null)
return null;
return new Date( issue.get("Sent On").getTime() + 14*24L*3600*1000 );

Here's how it works: it returns a new Date object from milliseconds calculated from the milliseconds in the Sent On date + 14 days x 24 hours x 3600 seconds * 1000 milliseconds.

[EDIT] changed "24" into "24L" to force Long calculations, otherwise the formula won't work past 24 days (because the number of milliseconds would be more than the maximum Integer value, 2^31-1)

Oh yes sorry I forgot to mention it is for the cloud version. Thank you for giving the server version info

Well, I knew it had to be on Jira Server because JMCF is only available for Jira Server, not Cloud...

I have confirmed this works!

Hey all -

After a little struggle,  I think this does the trick really well. Change out your custom field number and issue types.

<!-- Calculate new Date based on Custom Field Date Time and Issue Type  - David Hogan 04/09/2018
@@Formula:
String issueType = issue.get("issuetype").getName().toString();
var d = new Date(issue.get("customfield_XXXXXX").getTime());

if (issue.get("customfield_XXXXXX") == null){
return null;
}
if (issueType.equals("YOUR ISSUE TYPE NAME")) {
// subtract 14 days from calculated date time custom field
d.setDate(d.getDate() - 14);
return d;
}
if (issueType.equals("YOUR ISSUE TYPE NAME")) {
// subtract 30 days from calculated date time custom field
d.setDate(d.getDate() - 30);
return d;
}
-->
Your Calculated Description Goes Here

sidebar: thanks to those who contributed before me. Really appreciated. However, please note that the calculations of days*hours*seconds*milliseconds fail if greater than 24 days. Works great 1 through 24. If 25 days, it fails. 

That's correct. The formula should be altered slightly:

25*24L*3600*1000

to make sure calculations are done using Long instead of Integer. Otherwise, you reach the limit of Integers, which is 2^31-1 (a little over 2 billions).

Thanks, David!

For others, here you go, this version works great too.

<!-- Calculate new Date based on Custom Field Date Time and Issue Type  - David Hogan 04/09/2018
@@Formula:
String issueType = issue.get("issuetype").getName().toString();

if (issue.get("customfield_XXXXXX") == null){
return null;
}
if (issueType.equals("YOUR ISSUE TYPE NAME")) {
// subtract 14 days from calculated date time custom field
return new Date(issue.get("customfield_XXXXXX").getTime() - 14*24L*60*60*1000);
}
if (issueType.equals("YOUR ISSUE TYPE NAME")) {
// subtract 30 days from calculated date time custom field
return new Date(issue.get("customfield_XXXXXX").getTime() - 30*24L*60*60*1000);}

-->
Your Calculated Description Goes Here

David - thoughts on how to remove weekends and holidays efficiently?

There is another Community question about weekends (with a solution) but not Holidays. It also depends on how you define Holidays, obviously, which is why it's not an easy problem.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 29, 2018 in Marketplace Apps

How to set up an incident workflow from the VP of Engineering at Sentry

Hey Atlassian community, I help lead engineering at Sentry, an open-source error-tracking and monitoring tool that integrates with Jira. We started using Jira Software Cloud internally last year, a...

1,321 views 0 8
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