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

This widget could not be displayed.

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}})
This widget could not be displayed.

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.

This widget could not be displayed.

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.

This widget could not be displayed.

can we use this method to edit comment?

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

269 views 5 0
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