groovy 如何在scriptrunner中使用工作流转换的后置函数检索summary system字段的值

neskvpey  于 2022-11-01  发布在  其他
关注(0)|答案(1)|浏览(112)

我尝试使用ScriptRunner检索Jira中Summary系统字段的值。我在ScriptRunner中使用以下代码,但问题是def cf = customFieldManager.getCustomFieldObject("Summary")行返回的变量cf为空。我如何修复此问题并在ScriptRunner中检索summary字段的值?

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import org.apache.log4j.Logger

def log = Logger.getLogger("atlassian-jira.log")

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueManager = ComponentAccessor.getIssueManager()

def cf = customFieldManager.getCustomFieldObject("Summary")
log.warn("MOUNA 1: "+cf)

issue.setCustomFieldValue(cf, "mouna")
log.warn("MOUNA 2: "+issue)
yhxst69z

yhxst69z1#

Jira中的“摘要”字段不是自定义字段。
您可以直接从问题中访问“汇总”字段(和其它系统字段):

log.warn(issue.summary)

但是要在Post Function中更新它,您需要使用MutableIssue类:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.event.type.EventDispatchOption

def mIssue = (MutableIssue) issue

mIssue.setSummary("New Summary")

def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser() // Or you can get any user by using UserManager

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

当然,不要忘记在代码开头导入所需的类:

相关问题