Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Scriptrunner - Update custom timestamp field on issue update

Michael OConnor March 3, 2023

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()))

1 answer

0 votes
PD Sheehan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 6, 2023

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.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
AUG Leaders

Atlassian Community Events