Forums

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

ScriptRunner script to Update date/time field when a ticket is added to sprint?

Nikhil Guntupalli July 14, 2020

Business Justification: As a Product Owner of Project TIA, I need to be able to view the DateTime stamp of any story that has been put into the sprint after it has started, so that I can ensure the engineering teams are working on the right things and set the appropriate expectations with our business users.

 

I am trying to use Scripted Listener in which we can trigger events "Sprint Property Set Event" and I am trying to use the below script.

But the script is not working as expected.

Script:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder

import java.sql.Timestamp

Issue issue = issue
def change = event?.getChangeLog()?.getRelated("ChildChangeItem").find {it.field == "Sprint"}
if (change) {
    def cf = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Sprint Added")
    def changeHolder = new DefaultIssueChangeHolder()
    def now = new Timestamp(new Date().getTime())
    cf.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(cf), now),changeHolder)
}

 @A @Thanos Batagiannis [Adaptavist] Please help me out

1 answer

0 votes
Martin Bayer _MoroSystems_ s_r_o__
Community Champion
July 14, 2020

Is it working if you edit event type to "Issue updated"?

Nikhil Guntupalli July 14, 2020

Nope its not. 

Is there any issue in the script? Which I am missing

Martin Bayer _MoroSystems_ s_r_o__
Community Champion
July 14, 2020

I always suggest to add "logging" to the script. It can answer following questions

  • is listener executed?
  • is "change" property not null?

You can use log.error("something") and read your log files.

Suggest an answer

Log in or Sign up to answer