I have a custom listener script that copies certains fields from a Parent issue to all of it's Child issues via a certain link name. So if the Parent Issue changed CustomFieldA to value "ACB", all the linked Child issues also get updated to have CustomFieldA = "ACB"
The script works fine for custom fields, but I cannot get the system field "Priority" to act the same way. I have tried following examples from here which is the exact same method, but the Child issues will not update.
This is my script, I have scriptrunner version 7.9.0:
EDIT: additional info, i'm using trigger events Issue Created and Issue Updated. I had also attempted to use .setPriorityId, still no results
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
import com.atlassian.jira.util.ImportUtils
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()
def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
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();){
IssueLink issueLink = (IssueLink) outIterator.next()
//define fields needing to copy over
def customAChanged = false
def customAField = "Custom A"
def priorityChanged = false
def priorityField = "Priority"
//check to see if the fields were updated, and grab the latest history entry
def changeHistory = changeHistoryManager.getChangeHistories(issue)
def history = changeHistory.getAt(changeHistory.size() - 1)
for (def changeItem : history.getChangeItemBeans()){
if(changeItem.getField().equals(customAField)){
customAChanged = true
} else if (changeItem.getField().equals(priorityField)){
priorityChanged = true
}
}
//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"){
//update customA, this works
def customA = customFieldManager.getCustomFieldObjectsByName("Custom A").getAt(0)
def fieldConfigA = customA.getRelevantConfig(linkedIssue)
def issueValue = issue.getCustomFieldValue(customA)
def changeHolder = new defaultIssueChangeHolder()
customA.updateValue(null, linkedIssue, new ModifiedValue(linkedIssue.getCustomFieldValue(customA), issueValue), changeHolder)
}
//update priority << this is not working
if (priorityChanged){
def parentPri = issue.getPriority()
linkedIssue.setPriority(parentPri)
}
//update the issue
issueManager.updateIssue(currentUserObj, linkedIssue, EventDispatchOption.ISSUE_UPDATED, false)
boolean wasIndexing = ImportUtil.isIndexIssues()
ImportUtils.setIndexIssues(true)
indexService.reIndex(linkedIssue)
ImportUtils.setIndexIssues(wasIndexing)
}
}
}