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

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".

Andrei [errno] Community Champion Feb 17, 2016

for user-selector custom fields, with their username:

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

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 Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,775 views 11 18
Join discussion

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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot