Hello, I want to add a month duration to specific date but my code can only add duration until the end of the month. How can i resolve this ?
Thanks.
def issueManager = ComponentAccessor.getIssueManager()
//def issue = issueManager.getIssueObject("DEMO-48")
def mutableIssue = (MutableIssue) issue
def authenticationContext = ComponentAccessor.getJiraAuthenticationContext()
def user = authenticationContext.getLoggedInUser()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def optionsManager = ComponentAccessor.getOptionsManager()
def Calendar cal = Calendar.getInstance();
def endDateCF = customFieldManager.getCustomFieldObject("customfield_11334")
def whenShouldRestoreCF = customFieldManager.getCustomFieldObject("customfield_11335")
def fieldConfig = whenShouldRestoreCF.getRelevantConfig(issue)
def option1 = optionsManager.getOptions(fieldConfig).find {it.value == "1 week"}
def option2 = optionsManager.getOptions(fieldConfig).find {it.value == "2 week"}
def option3 = optionsManager.getOptions(fieldConfig).find {it.value == "3 week"}
if( issue.getCustomFieldValue(whenShouldRestoreCF) == option1){
def newUpdate = new Timestamp(cal.getTimeInMillis()+ 7*1000*24*60*60);
mutableIssue.setCustomFieldValue(endDateCF, newUpdate)
}
if( issue.getCustomFieldValue(whenShouldRestoreCF) == option2 ){
def newUpdate = new Timestamp(cal.getTimeInMillis()+ 14*1000*24*60*60);
mutableIssue.setCustomFieldValue(endDateCF, newUpdate)
}
if( issue.getCustomFieldValue(whenShouldRestoreCF) == option3 ){
def newUpdate = new Timestamp(cal.getTimeInMillis()+ 21*1000*24*60*60);
mutableIssue.setCustomFieldValue(endDateCF, newUpdate)
}
issueManager.updateIssue(user, mutableIssue, EventDispatchOption.DO_NOT_DISPATCH, false)
Hi @Gökberk Karaca ,
you can use add method for Calendar :
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.WEEK_OF_YEAR, 2); //Add two week to the current date
Timestamp valueForCF = new Timestamp(calendar.getTimeInMillis());
mutableIssue.setCustomFieldValue(endDateCF, newUpdate)
This should fix your issue.
Fabio
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.