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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
David - thoughts on how to remove weekends and holidays efficiently?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Oh yes sorry I forgot to mention it is for the cloud version. Thank you for giving the server version info
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Well, I knew it had to be on Jira Server because JMCF is only available for Jira Server, not Cloud...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I need some assistance with this too, did you find a solution by any chance?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.