How can I get a ScriptRunner Script to log change history when executed?
Asked by Daniel Durand:

Good morning,   
I am running a script to update the data of an issue, the script runs correctly but the problem comes when it finishes since it does not show me the update of the field in the change history of the issue. I send you the code and an assurance that its execution does not leave a trace in the history.  
I would like to know if there is an option to leave a trace in the history of changes and how to do it or how to add it to the code.  

The code by which I make the query is the following:  

<br />

import com.atlassian.jira.component.ComponentAccessor  
import com.atlassian.jira.bc.issue.search.SearchService  
import com.atlassian.jira.jql.parser.JqlQueryParser  
import com.atlassian.jira.issue.Issue  
import com.atlassian.jira.issue.MutableIssue  
import com.atlassian.jira.event.type.EventDispatchOption  
import groovy.transform.BaseScript  
import com.atlassian.jira.issue.ModifiedValue  
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder  
import com.onresolve.scriptrunner.runner.customisers.ContextBaseScript  

@BaseScript ContextBaseScript script  

def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)  
def searchService = ComponentAccessor.getComponent(SearchService)  
def issueManager = ComponentAccessor.getIssueManager()  
def customFieldManager = ComponentAccessor.customFieldManager  
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()  

final String codigoDocumentoCustomFieldName = "C?digo Spring"  

Double nuevoCodigo = 1235.0  

//Issue issue = event.getIssue()  
Issue issue = getIssueOrDefault("BU-8682")  
def codigoDocumentoCustomField = customFieldManager.getCustomFieldObjects(issue).find { it.name == codigoDocumentoCustomFieldName }  

MutableIssue mIssue = (MutableIssue) issue  
issue.getSummary()  

codigoDocumentoCustomField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(codigoDocumentoCustomField), nuevoCodigo), new DefaultIssueChangeHolder())  

ComponentAccessor.getIssueManager().updateIssue(user, mIssue, EventDispatchOption.ISSUE_UPDATED, false)


Answers:
author: Joseph Chung Yin
body: [@Daniel Durand](/t5/user/viewprofilepage/user-id/5480843) -

Welcome to the community. If your script is updating an issue, if you access the issue via the UI, there should always be an entry in the Activity section for the action. Is that what you are asking for?

You can also contact Adaptavist (vendor) directly for their technical support - [https://marketplace.atlassian.com/apps/6820/scriptrunner-for-jira?hosting=datacenter\&tab=support](https://marketplace.atlassian.com/apps/6820/scriptrunner-for-jira?hosting=datacenter&tab=support)

Hope this helps.

Best, Joseph Chung Yin


author: Nicolas Grossi
body: [@Daniel Durand](/t5/user/viewprofilepage/user-id/5480843) You also take a look at this thread: <https://community.atlassian.com/t5/Jira-questions/Update-change-history/qaq-p/1284671>

HTH

Nicolas

comments: author: Matt Doar _Adaptavist_
body: I think <https://community.atlassian.com/t5/Jira-questions/Re-Update-Issue-s-History-tab-after-listener-script-make/qaq-p/2084751/comment-id/758828#M758828> is on the right track with the validationResult. That will both update the issue and the issue history


Tags: jira-data-center

scriptrunner