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
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Thursday in Agile

How Davin Studer gets Confluence to do everything he wants it to do...except dishes

  @Davin Studer holds many interests, including but not limited to health tech and Star Trek. Read on to discover more about Davin, from his favorite Confluence macros to his favorite lit...

154 views 1 7
Read article

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