You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Jira数据库值选择型自定义字段取值代码异常求助

解决Jira数据库值选择型自定义字段获取显示值的问题

你拿到的1000547是该字段存储的内部ID,不是界面显示的文本——这类数据库值选择型自定义字段不会直接存储界面上的显示内容,而是用内部ID关联对应的显示值,所以直接强转成String只能拿到ID。

修改后的Groovy代码

def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_10790")
def fieldValue = issue.getCustomFieldValue(customField)

if (fieldValue) {
    // 调用字段值对象的显示值方法,不同插件实现可能方法名不同,常见的有getDisplayValue()/getLabel()
    def displayValue = fieldValue.getDisplayValue()
    log.warn("MOUNA CAMELIA VALUE " + displayValue)
} else {
    log.warn("MOUNA CAMELIA VALUE: 该字段无值")
}

额外排查步骤

如果不确定调用哪个方法,可以先打印字段值的类型,再根据类名找对应的显示方法:

def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_10790")
def fieldValue = issue.getCustomFieldValue(customField)
if (fieldValue) {
    log.warn("字段值类型: " + fieldValue.getClass().getName())
}

比如如果输出类型是com.onresolve.jira.groovy.jql.values.DatabaseValue,那getDisplayValue()就是正确的方法;如果是其他类,对应找获取显示文本的方法即可。

内容的提问来源于stack exchange,提问作者منى

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 09:14:59