Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Update custom field using jira-python

Chris Kast
Contributor
September 21, 2014

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

2 votes
Answer accepted
Chris Kast
Contributor
September 29, 2014

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]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 17, 2016

for user-selector custom fields, with their username:

issue.update(fields={'customfield_10000': {'name': userid}})
mika nokka October 1, 2018

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

Like # people like this
1 vote
Chris Kast
Contributor
September 29, 2014

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.

0 votes
kz1212 October 9, 2017

can we use this method to edit comment?

0 votes
thierry mallard October 24, 2014

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

Chris Kast
Contributor
October 24, 2014

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.

Suggest an answer

Log in or Sign up to answer