我有一段代码。我可以查看所有值,但是在更新新链接的问题的“节奏”“帐户”字段时,什么也没发生。我正在使用Scriptrunner For Jira的自定义监听器
我希望新链接的问题(issueInEpic)的Tempo“帐户”字段(linkedField)值(oldCfValue)更新为Epic的“帐户”字段值的值(newCfValue)。
log.info()正确显示所有值。唯一的问题是更新链接的问题。
import com.atlassian.jira.event.issue.link.IssueLinkDeletedEvent
import org.apache.log4j.Logger
import org.apache.log4j.Level
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.index.IssueIndexingService
import com.atlassian.jira.util.ImportUtils
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.util.IssueChangeHolder
def log = Logger.getLogger(com.atlassian.jira.event.issue.link.IssueLinkCreatedEvent)
log.setLevel(Level.INFO)
if ([IssueLinkCreatedEvent].contains(event.getClass())) {
if (event.issueLink.issueLinkType.name == "Epic-Story Link") {
def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def issueManager = ComponentAccessor.getIssueManager()
def cfManager = ComponentAccessor.getCustomFieldManager()
def accountField = cfManager.getCustomFieldObjects(event.issueLink.sourceObject)?.find{it.name == "Account"}
def linkedField = cfManager.getCustomFieldObjects(event.issueLink.destinationObject)?.find{it.name == "Account"}
MutableIssue issueInEpic = event.issueLink.destinationObject as MutableIssue
MutableIssue epic = event.issueLink.sourceObject as MutableIssue
def newCfValue = accountField.getValue(epic)
def oldCfValue = linkedField.getValue(issueInEpic)
issueInEpic.setCustomFieldValue(linkedField, newCfValue)
issueManager.updateIssue(currentUser, issueInEpic, EventDispatchOption.DO_NOT_DISPATCH, false)
def issueIndexingService = ComponentAccessor.getComponent(IssueIndexingService.class)
def wasIndexing = ImportUtils.isIndexIssues()
ImportUtils.setIndexIssues(true)
issueIndexingService.reIndex(event.issueLink.destinationObject)
ImportUtils.setIndexIssues(wasIndexing)
log.info(accountField)
log.info(newCfValue)
log.info(oldCfValue)
log.info(issueInEpic)
log.info(epic)
log.info(linkedField)
}
}