Groovy脚本,用于递增(summend文本字段)自定义字段的值

bfhwhh0e  于 2022-11-21  发布在  其他
关注(0)|答案(1)|浏览(136)

问题陈述:我想设置自定义脚本后置函数,以便在特定工作流程转换时将自定义字段(文本字段)增加+1,例如,当转换从固定状态启动时-将Program、Label和External字段增加+1。
方法:(自定义脚本post函数)
字段已创建:脚本字段(程序、标签和外部)-文本字段
版本:吉拉8.20.6

我正在使用的Groovy脚本引发错误:

import com.atlassian.jira.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.customfields.CustomFieldType
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.util.IssueChangeHolder
 
ComponentManager componentManager = ComponentManager.getInstance()
CustomFieldManager customFieldManager = componentManager.getCustomFieldManager()
CustomField cf = customFieldManager.getCustomFieldObject("customfield_11727")
Double val = (issue.getCustomFieldValue(cf) as Double)
if ( val == null) 
 val = 1
else
 val = val + 1
IssueChangeHolder changeHolder = new DefaultIssueChangeHolder();
cf.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(cf),val), changeHolder)

从Script Runner主控台取得时发生错误:“* 无法解析类别ComponentManager*”

gcuhipw9

gcuhipw91#

ComponentManager已过时,如Manu Mishra所述
替换为:

ComponentManager componentManager = ComponentManager.getInstance()
CustomFieldManager customFieldManager = componentManager.getCustomFieldManager()

与此:

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()

并替换import语句:

import com.atlassian.jira.ComponentAccessor

至:

import com.atlassian.jira.component.ComponentAccessor

相关问题