Update custom field using jira-python

We're in the process of migrating from Bugzilla to JIRA. In our Bugzilla instance, we have a custom drop-down field that lists a bunch of versions. That gets imported fine but as a JIRA custom drop-down. What I'd like to do, for each issue, is that the value of custom drop-down and put it in a new "version picker" custom field. I'm trying to use the jira-python client to do this but running into problem. See the code below. it doesn't error out when I do this but it's not updating the new version picker field. Any thoughts?

jira = JIRA({'server': DEFAULT_JIRA_SERVER}, basic_auth=(DEFAULT_JIRA_USER, DEFAULT_JIRA_PASS))

issues_to_mod = jira.search_issues('filter=filter_alerts', maxResults=200)

print 'Will update', str(len(issues_to_mod)), 'issues.'

for issue in issues_to_mod:
	old_fixed_version = issue.fields.customfield_10105
	old_fixed_version_string = str(old_fixed_version[0])
	print 'Updating issue', issue, 'with value', old_fixed_version_string
	issue.update(fields={'customfield_10400': {'value': old_fixed_version_string}})

4 answers

1 accepted

1 vote
Accepted answer

Huzzah!! My original code sample was correct except for one word: "value" needed to be replaced with "name". So the correct code is:

jira = JIRA({'server': DEFAULT_JIRA_SERVER}, basic_auth=(DEFAULT_JIRA_USER, DEFAULT_JIRA_PASS))
 
issues_to_mod = jira.search_issues('filter=filter_alerts', maxResults=200)
 
print 'Will update', str(len(issues_to_mod)), 'issues.'
 
for issue in issues_to_mod:
    old_fixed_version = issue.fields.customfield_10105
    old_fixed_version_string = str(old_fixed_version[0])
    print 'Updating issue', issue, 'with value', old_fixed_version_string
    issue.update(fields={'customfield_10400': {'name': old_fixed_version_string}})

For those who care, I figured it out by looking at the REST examples here. Each custom field type has a specific data structure. In the case of version-picker fields, the value can be referenced by either the version "name" or "id".

for user-selector custom fields, with their username:

issue.update(fields={'customfield_10000': {'name': userid}})

Thanks! I was totally lost with "how to set Multiselect" custom field using Python Jira.

I had a look the REST examples you pointed and found a solution (setting Multiselect requires data in array)

like this

issue.update(fields={'customfield_10007': [{'value':'035M'}]})

Ping...

Anyone? It's frustrating because the code "works" in the sense that it exits with 0. It's just the field is not getting updated.

Hi,

 

Sorry for late answer.

Don't you need  to create version object using jira.create_version()? That is what needs to be done when using JIRA from browser.

 

BR

Thanks, Thierry. I got it figured out (see above). To answer your question, we shouldn't need to create a version object since it's already there (the versions were imported as a part of the BZ import process). What I'm doing here is basically converting that object name (the version) into a string and then assigning that string as a value to the custom field.

can we use this method to edit comment?

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Wednesday in Jira

Make your Atlassian Cloud products more secure: our NEW admin security guide

Hey admins! I’m Dave, Principal Product Manager here at Atlassian working on our cloud platform and security products. Cloud security is a moving target. As you adopt more products, employees consta...

90 views 0 4
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you