It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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
TAGS

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you