I'm using Scriptrunner version 6.54.0 for Jira Server, and I have a custom listener script already built.
It takes a parent issue, looks for a specific link type, finds the child issues in that link type, and any updates made on the parent custom field will be copied down to the child's custom field. That part works, but whenever the listener script runs, on the child issue's History tab under Activity in Jira, it doesn't show any changes made.
I have looked up references and other questions with similar issues like this: https://community.atlassian.com/t5/Jira-questions/Update-Custom-Value-from-Calculated-Field-using-quot/qaq-p/1059907
But their suggestions does not work. My script still doesn't update the child issue's History tab. I don't need history change to show up on the database. It should be visible for the users on the issue's History tab.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.index.IssueIndexingService
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.Customfield
import com.atlassian.jira.issue.history.ChangeLogUtils
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueManager = ComponentAccessor.getIssueManager()
def optionsManager = ComponentAccessor.getComponent(OptionsManager)
def issue = event.issue
def indexService = ComponentAccessor.getComponent(IssueIndexingService.class)
def changeLog = even?.changeLog
def issueChanges = issueManager.getIssueObject(issue.id)
def currentUserObj = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
if(issue.issueType.name == "Parent"){
//loop through parent links
List<IssueLink> allOutIssueLunk = ComponentAccessor.getIssueLinkManager().getInwardLinks(issue.getID())
for (Iterator<IssueLink> outIterator = allOutIssueLink.iterator(); outIterator.hasNext();0{
IssueLink issueLink = (IssueLink) outIterator.next()
//only update field if the link is a clone
if (issueLink.getIssueLinkType().getName() == "Cloners"){
MutableIssue linkedIssue = issueLink.getSourceObject() as MutableIssue
//only update child issues
if (linkedIssue.issueType.name == "Child"){
//get custom field A which is a Select List multiple choice type
def customA = customFieldManager.getCustomFieldObjectsByName("Custom A").getAt(0)
def fieldConfigA = customA.getRelevantConfig(linkedIssue)
//get value of parent
def issueValue = issue.getCustomFieldValue(customA)
//update child issue of parent's custom field
def changeHolder = new defaultIssueChangeHolder()
customA.updateValue(null, linkedIssue, new ModifiedValue(linkedIssue.getCustomFieldValue(customA), issueValue), changeHolder)
//changes should appear on issue's History tab and tell Jira to reindex so that change is searchable
ChangeLogUtils.createChangeGroup(currentUserObj, issue, issue, changeHolder.getChangeItems(), false)
boolean wasIndexing = ImportUtil.isIndexIssues()
ImportUtils.setIndexIssues(true)
indexService.reIndex(linkedIssue)
ImportUtils.setIndexIssues(wasIndexing)
}
}
}
}
I imagine the last part I'm doing something wrong. Please let me know what changes need to be made so that updates appear on issue's History tab.