Update jira issue Change history based on issue field value update

Please some one help me on my below request.

I'm using  field " Story Points" on issue create/view/edit form.

I have writen script runner listener to copy value from "Story Point" to "Points" field , whenenver "Story Point" is edited, it's updating "Points" field value as expected .But problem is that when i try to generate JIRA Version report in scrum board using "Points" value as estimation then updated value treated as original date only not taking updated date to drawing version report.

Here is my scriptrunner lister code

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

def issue = event.issue as Issue

def cf = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Story Points");

def sp = issue.getCustomFieldValue( cf ) ?: 0

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def tgtField = customFieldManager.getCustomFieldObjects(event.issue).find {it.name == "Points"}
def changeHolder = new DefaultIssueChangeHolder()
tgtField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(tgtField),(double)sp),changeHolder)

 

Is there any way to update issue change history along with "Points" field value ?

Please help me.

1 answer

You may simply need to use the IssueService to update the issue in order to make sure that all the normal business logic events are getting fired properly. Make sure to put a good condition on your listener so that you don't end up in an infinite loop where the listener keeps triggering itself.

Starting from your script, something like this should work:

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor

def issue = event.issue as Issue
def cf = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Story Points");

def sp = issue.getCustomFieldValue( cf ) ?: 0
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def tgtField = customFieldManager.getCustomFieldObjects(issue).find {it.name == "Points"}

def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issueService = ComponentAccessor.getIssueService()
def issueInputParameters = issueService.newIssueInputParameters()
issueInputParameters.with {
    addCustomFieldValue(tgtField.idAsLong, sp.toString())
}
def updateValidationResult = issueService.validateUpdate(currentUser, issue.id, issueInputParameters)
if (updateValidationResult.isValid()) {
    issueService.update(currentUser, updateValidationResult)
}

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted 5 hours ago in Featured Groups

Tuesday tips & tricks: What is the Atlassian Community?

It's officially Tuesday, which means it's officially time for another tip to help you better navigate this space we call the Atlassian Community. 😄 I got a great question from community member, Sa...

15 views 0 1
View post

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you