繁体   English   中英

如何在Jira中获取自定义字段的选项?

[英]How to get the options for a custom field in Jira?

在我正在研究的Jira问题中,有些字段带有有效值的下拉列表。 我想使用python访问该下拉列表。 查看问题的返回字段时,该对象具有值customfield_14651 ,该值是具有valueid的对象。 Jira文档显示有一个custom_field_option()方法应返回字段? 我调用如下方法:

self.jira = JIRA('https://jira.companyname.com',basic_auth (login['username'], login['password']) )
print self.jira.custom_field_option('14651')

并收到以下错误: response text = {"errorMessages":["A custom field option with id '14651' does not exist"],"errors":{}}

Jira具有.fields()函数,该函数返回您正在使用的帐户可见的所有字段的列表。

from jira import JIRA

jira = JIRA(basic_auth=('username', 'password'), options = {'server': 'url'})

# Fetch all fields
allfields = jira.fields()

# Make a map from field name -> field id
name_map = {field['name']:field['id'] for field in allfields}  

现在, name_map是格式为{"field name":"customfield_xxxx", ... }的字典

看起来在API中执行此操作的方法是:

from jira import JIRA
jira = JIRA(basic_auth=('username', 'password'), options = {'server': 'url'})

# get an example issue that has the field you're interested in 
issue = jira("PRJ-1")
meta = jira.editmeta(issue)

# inspect the meta to get the field you want to look at
allowed_values = [v['value'] for v in meta['fields']['customfield_99999']['allowedValues']]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM