Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How can I get a ScriptRunner Script to log change history when executed?

Daniel Durand
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 12, 2024

 

 

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:


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)

2 answers

0 votes
Joseph Chung Yin
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 12, 2024

@Daniel Durand -

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

Hope this helps.

Best, Joseph Chung Yin

0 votes
Nicolas Grossi
Banned
July 12, 2024
Matt Doar _Adaptavist_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 12, 2024

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

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events