14

How do you determine the name of a custom field in jira-python?

When I retrieve an issue, my custom fields show up as customfield_xxx

The names on my screen are 'project', 'name', 'due date', etc. Short of putting a value in each field, then seeing where it appears when I re-read the issue.

That is I can put 'a' in one of my fields, then read the issue, and find that customfield_10801 (or whatever) has the value 'a'. But is there a general way to find, for example, if my custom field is 'due date', which customfield_xxx does it get mapped to?

Or, in the JIRA GUI, how would I look up these customfield #'s.

Paul Nelson
  • 1,291
  • 4
  • 13
  • 20

1 Answers1

27

From the GUI you can see the custom field id in the html code or url:

  • On the admin page where all the custom fields are listed on the row of the custom field you are interested to the right click the gear and click/hover over "Configure". You should see the custom field ID in the URL.

Another way is via the REST API:

  • {jira-base-url}/rest/api/2/field
  • It's a GET request so just put that url in your browser.

Update:

Based on the comments it can be done something like this:

# Fetch all fields
allfields=jira.fields()
# Make a map from field name -> field id
nameMap = {field['name']:field['id'] for field in allfields}
# Fetch an issue
issue = jira.issue('ABC-1')
# You can now look up custom fields by name using the map
getattr(issue.fields, nameMap[custom_name])
Zitrax
  • 19,036
  • 20
  • 88
  • 110
LukeSolar
  • 3,795
  • 4
  • 32
  • 39
  • Thanks LukeSolar. That works. I was hoping I could make it programmable. I use REST in jira-python, and it seems the only data you can get from the customfield_xxx is the id,url, and value. Not 'name'. – Paul Nelson Nov 21 '14 at 14:19
  • Your comment about the URL made me realize that the data is at the server level, not project or issue level. In python, this will make a name-->number dictionary: – Paul Nelson Nov 21 '14 at 15:03
  • 2
    allfields=jira.fields(); nameMap = {field['name']:field['id']} for field in allfields} – Paul Nelson Nov 21 '14 at 15:04
  • hey this command helps to get list of all fields of all the projects, pls help me to find fields of a particular project..(i know the project key) – lazy rabbit Jun 28 '15 at 12:58
  • @PaulNelson I updated the answer based on your comment – Zitrax Oct 12 '15 at 12:11
  • this is awesome! one question on it though. What if you use the same field name in two different boards? – apinostomberry Apr 07 '23 at 01:05