Forums

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

(jira script runner listener) can't detect changes to Time Tracking's "Original Estimate" field

Deleted user June 21, 2018

Hi,

I'm trying to detect changes to Time Tracking's "Original Estimate" field of an issue, so that if a change was detected - it will update a custom value (called "Original Issue Estimate").

To achieve that, I'm using Script-runner - Script listener. (my jira version is 7.9.0)

I listen to "Issue Updated" event & use the following code:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.project.version.Version
import com.atlassian.jira.bc.project.component.ProjectComponent

import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder

log.warn("Issue updated event triggered listener")

IssueManager issueManager = ComponentAccessor.getIssueManager()
def issue = event.getIssue()

if(event.issue.issueType.name == "Task" || event.issue.issueType.name == "Bug"){

def isOriginalEstimateChanged = event?.getChangeLog()?.getRelated("ChildChangeItem").find {it.field == "timetracking_originalestimate"}
log.warn("isOriginalEstimateChanged =" + isOriginalEstimateChanged)

if(isOriginalEstimateChanged){
//if(true){

log.warn("changed to timetracking_originalestimate detected ")

def changeHolder = new DefaultIssueChangeHolder()

def origEstimateField = ComponentAccessor.getFieldManager().getField("timetracking_originalestimate")
log.warn("timetracking_originalestimate value is (in seconds): " + issue.getOriginalEstimate().toString())
def fValue = issue.getOriginalEstimate().doubleValue()

def origEstimateInHours = fValue / 28800
log.warn("timetracking_originalestimate value is (in hours): " + origEstimateInHours)

def origIssueEstimate = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Original Issue Estimate")

origIssueEstimate.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(origIssueEstimate), origEstimateInHours), changeHolder)
}

}

However, I can't seem to detect the change to the "Original Estimate" field - 

when I change its value (via the edit issue screen") nothing get's updated & it doesn't get inside the following condition:

if(isOriginalEstimateChanged){

 

When I change the condition to be:

if(true){

It does update my custom field, so I guess I do something wrong in the way I try to detect a change to "Original Estimate" field:

def isOriginalEstimateChanged = event?.getChangeLog()?.getRelated("ChildChangeItem").find {it.field == "timetracking_originalestimate"}

 

I already used the same method to detect changes to other fields ("Fix Version", "Components") successfully, so I do not know what I'm messing up here...

 

Any help would be appreciated.

2 answers

1 accepted

1 vote
Answer accepted
Mark Markov
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.
June 21, 2018

Hello @[deleted]

 

Original estimate field have different name:

try

def isOriginalEstimateChanged = event?.getChangeLog()?.getRelated("ChildChangeItem").find {it.field == "timeoriginalestimate"}
Deleted user June 21, 2018

Thank you very much, that did the trick!

Dan27
Contributor
December 9, 2018

Hello @Mark Markov ,

How can I use this line to a custom field ID ? instead custom field name?

 

Thanks! :) 

1 vote
Alexey Matveev
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.
June 21, 2018

Hello,

Try to log the contents for the changelog to the atlassian-jira.log and have a look what is inside the object:

log.error("event?.getChangeLog(): ${event?.getChangeLog().toString()}")

Deleted user June 21, 2018

Thanks Alexey, as Mark said, I got the field name wrong. 

Like Mykola Vysochyn likes this
Alexey Matveev
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.
June 21, 2018

But if you have a look in the logs, you can find all names for the field. It will help to solve futher problems

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events