I have a script that works really well to subtract days from a custom field. That is, until I need to subtract more than 24 days.
Here are the details:
customfield_14082 = 2018-09-15 00:00
Subtracting 14 days script returns 2018-09-01 00:00 - PERFECT! Works 1 thru 24 days.
Subtracting 25 (or greater same issue) returns 2018-10-9 17:02 - What? Why?
Here is the script:
<!-- Subtracts two weeks from the New Business Date (customfield_14082) - David Hogan 04/06/2018
@@Formula:
if (issue.get("customfield_14082") == null)
return null;
long ms = issue.get("customfield_14082").getTime() - 25*24*60*60*1000;
date = new Date(ms);
return date;
-->
Any assistance appreciated!
David
I presume the script is using the groovy interpreter, and if that's the case then it's very easy to subtract the days and the get the correct answer.
Sample - to subtract 25 days
use (groovy.time.TimeCategory) {
def date = new Date()
println date
println date-25.days
}
https://stackoverflow.com/questions/8816990/subtract-a-date-by-1-or-2-in-groovy
And it's super easy in groovy to get date object from the String using Date.parse method
Sample here - http://rmr.wikia.com/wiki/Groovy_Date_Parsing_and_Formatting
Thus, once you have the date object (after converting string format of customField.value()) then you can just subtract the 25 days and that should get you the correct value as that is more idiomatic way of doing things.
Thanks for the reply, Tarun!
After some troubleshooting, I came up with this.
<!-- 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;
}
-->
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @David Hogan
Is this working now for you?
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.
Glad that it's working, could you please upvote/accept the answer so that other users with similar issue at hand are helped.
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.