jira python customfield

Paul Nelson picture Paul Nelson · Nov 19, 2014 · Viewed 11.6k times · Source

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.

Answer

LukeSolar picture LukeSolar · Nov 21, 2014

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])