Hi
I have custom field in jira, and I want get value in custom field
example in jira
custom field : week
custom field value : monday, tuesday, wednesday, thursday, friday, saturday, sunday
custom field id : customfield10003
example in python
after jira login
customFieldValue = jira.fields.customfield10003.value
or
customFieldValue = jira.fields.week.value
print(customFieldValue)
output print: [monday, tuesday, wednesday, thursday, friday, saturday, sunday]
but it's not working
how can I work this code?
thank u
Hi @이창호 ,
Based on the example you have provided, it seems you are using https://jira.readthedocs.io/en/master/ . If so, you could do something similar to:
# 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])
Please, make sure the custom field you are trying to get is visible and searchable in the Jira Issue. You can run a REST API call against a particular issue key (e.g ABC-1) reviewing if the custom field you are after is available:
https://docs.atlassian.com/software/jira/docs/api/REST/7.12.0/#api/2/issue-getIssue
GET /rest/api/2/issue/{issueIdOrKey}
Kind regards,
Rafael
thank for your answer
i tried
allfields = jira.fields()
idnameMap = {jira.field['name']:jira.field['id'] for jira.field in allfields}
getValues = allfields(issue.fields, idnameMap["customfield_10012"])
but it's not working
where did I go wrong?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
allfields = jira.fields()
nameMap = {jira.field['name']:jira.field['id'] for jira.field in allfields}
getvalue = getattr(issue.fields, nameMap["week"])
print(getvalue)
#I wanted output : monday, tuesday, wednesday, thursday, friday, saturday, sunday
#but this code output is : monday
I tried your code
but i got the just one value
I need all value in field
thank you
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @이창호 ,
You forgot to search for an issue:
issue = jira.issue('ABC-1')
Output idnameMap to the console and review if the custom field you are after (e.g customfield_10012) is present in the object.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I excuted code when after search issue
issue = jira.issue('EX-221')
allfields = jira.fields()
nameMap = {jira.field['name']:jira.field['id'] for jira.field in allfields}
getvalue = getattr(issue.fields, nameMap["week"])
print(getValue)
#output "monday"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @이창호 ,
Based on comment:
"#I wanted output : monday, tuesday, wednesday, thursday, friday, saturday, sunday
#but this code output is : monday"
What you want is not the customField value but the options available to the custom field. Therefore, you should be looking at metadata instead.
Here is an example on how to get metadata from Select List (cascading) com.atlassian.jira.plugin.system.customfieldtypes:cascadingselect:
from jira import JIRA
import re
options = {'server': 'http://localhost:8080/jira'}
jira = JIRA(options, basic_auth=('admin', 'admin'))
# get an example issue that has the field you're interested in
issue = jira.issue("ABC-1")
# get the metadata
meta = jira.editmeta(issue)
# this is the customField I have created
# Select List (cascading) com.atlassian.jira.plugin.system.customfieldtypes:cascadingselect
allowedValues = meta['fields']['customfield_10300']['allowedValues']
for options in allowedValues:
print(options['value'])
Kind regards,
Rafael
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have one more question T.T
if have child data in customField
{'id': 'customfield_10003', 'key': 'customfield_10003', 'name': 'week'
'schema': {'type': 'option-with-child', 'custom': 'com.atlassian.jira.plugin.system.customfieldtypes:cascadingselect', 'customId': 10003}}
like
customField : week
data : monday, tuesday, wednesday, thursday, friday, saturday, sunday
child data : hour, minuit, second
allowedValues = meta['fields']['customfield_10300']['allowedValues']
print(allowedValues )
# output : monday, tuesday, wednesday, thursday, friday, saturday, sunday
# and I need more data : hour, minuit, second
how can I get with child data in customField?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
from jira import JIRA
# Connect to Jira
jira = JIRA(server='https://your-jira-instance.com', basic_auth=('username', 'password'))
# Get the issue
issue = jira.issue('PROJECT-123')
# Get the custom field metadata (if needed)
field_id = 'customfield_10003'
field_meta = jira.field(field_id)
# Get the allowed values
allowed_values = getattr(issue.fields, field_id).allowedValues
# Print all options with children
print("Available options:")
for parent in allowed_values:
print(f"\nParent: {parent.value}")
if hasattr(parent, 'children') and parent.children:
print("Children:")
for child in parent.children:
print(f" - {child.value}")
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @이창호
You haven't said whether this is a server or cloud instance, although I'm not sure that it makes much difference.
I think that you need an underscore "_" after field so that it becomes
customFieldValue = jira.fields.customfield_10003.value
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.