Hi,
I have a target date, which I needs to reduce 2 days during the transition. How I can do it using postfunction.
My target date 10/1/2019 so I would like to set 9/29/2019.
I am getting the value of target date by
def TD = customFieldManager.getCustomFieldObjectByName("Target Date")
def TDV = issue.getCustomFieldValue(TD)
but unable to subtract it. How I can do that? Any advise.
Thanks,
Om
try something like this, iirc you can just subtract a number from timestamp and groovy will understand
last piece is for updating issue, though if it's a postfunction last line is not necessary
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.component.ComponentAccessor
def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def TD = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Target Date")
def TDV = issue.getCustomFieldValue(TD)
TDV -= 2
issue.setCustomFieldValue(TD, TDV)
ComponentAccessor.issueManager.unpdateIssue(currentUser, issue, EventDispatchOption.ISSUE_UPDATED, false)
@Ilya TurovIt doesn't work but I did by converting to date and string as below.
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.component.ComponentAccessor
def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def TD = customFieldManager.getCustomFieldObjectByName("Target Date")
def TDV = issue.getCustomFieldValue(TD)
Date newTDV = (Date)TDV
def newDateformat = newTDV.format('MM/dd/yyyy')
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
cal.setTime(sdf.parse(newDateformat));
cal.add(Calendar.DATE, -2);
Timestamp DefTDD = new Timestamp(cal.getTimeInMillis())
issue.setCustomFieldValue(TD, DefTDD)
issueManager.updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED ,false)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I made a typo, should be
issueManager.updateIssue(...
not unpdateIssue, but anyway, if this postfunction is first in list (before the one that stores issue to db) you don't need to manually update it
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.