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.
Hello @[deleted]
Original estimate field have different name:
try
def isOriginalEstimateChanged = event?.getChangeLog()?.getRelated("ChildChangeItem").find {it.field == "timeoriginalestimate"}
Thank you very much, that did the trick!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Mark Markov ,
How can I use this line to a custom field ID ? instead custom field name?
Thanks! :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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()}")
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Alexey, as Mark said, I got the field name wrong.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
But if you have a look in the logs, you can find all names for the field. It will help to solve futher problems
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.