I'm trying to update a timestamp field "end date" with the value of another timestamp field "deployment" + a duration "minutes" field. I can do this in the workflow with a groovy script in JMWE, but I want it to trigger on any issue creation/update if those two fields are actually populated, not just as part of the workflow.
Below is the groovy expression for the update value in a workflow which seems to work.
new java.sql.Timestamp(issue.get("customfield_14025").getTime() + java.util.concurrent.TimeUnit.MINUTES.toMillis(issue.get("customfield_14032").toInteger()))
Here is a quick sample script (using system field 'created' instead for simplicity) that shows how I would achieve the calculation using TimeCagetory:
import groovy.time.TimeCategory
import com.atlassian.jira.component.ComponentAccessor
def issue = ComponentAccessor.issueManager.getIssueObject('XXX-nnnn')
def ts = issue.created
def minutes = 120
def minutesDuration = TimeCategory.getMinutes(minutes)
def calculatedDate = TimeCategory.plus(ts , minutesDuration)
def calculatedTs = calculatedDate.toTimestamp()
If you are looking to have this happen each time the date or the minutes field are changed, then you will need to create a Custom Event Listener.
Perhaps something like this. Note that this will not capture a change history for field changes as a result of this scrip not re-index the changed field. You'll need to trigger that manually.
I'd strongly recommend looking at the new scriptrunner api called HAPI. This should be a lit easier to do.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.