Update custom field using Jira Python

Rameez Rahman March 25, 2013

I have a custom field named "Detailed Status" of the type Text Field (< 255 characters) with custom field ID value of 10000. I am writing a JIRA Python script to update the value of this custom field of a number of issues having a particular value for this field.

Lets say I want to update all the issues having the custom field value as "Test Value" with another value called, say, "New Value".

I am just getting started on JIRA Python scripting, so based on what I read on documentation, this is how my code looks like as of now.

from jira.client import JIRA
jira_options={'server': 'http://localhost:8080'}
jira=JIRA(options=jira_options,basic_auth=('usrname','pwd'))
for issue in jira.search_issues(' cf[10000] = "Test Value" ', maxResults=3):
    issue.update(fields={'cf[10000]': 'New Value'})

This threw the following error

Traceback (most recent call last):
  File "test.py", line 11, in &lt;module&gt;
    issue.update(fields={ 'cf[10000]' : 'New Value'})
  File "C:\Python27\lib\site-packages\jira\resources.py", line 193, in update
    super(Issue, self).update(**data)
  File "C:\Python27\lib\site-packages\jira\resources.py", line 72, in update
    raise_on_error(r)
  File "C:\Python27\lib\site-packages\jira\exceptions.py", line 29, in raise_on_
error
    error = errorMessages[0]
IndexError: list index out of range

I tried updating the custom field with its name, but couldnt get it working too. Could you please tell me the correct syntax/way to update a custom field through Jira Python script? Couldnt find any examples in the documentation as well.

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

5 votes
Answer accepted
DanielP
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.
March 25, 2013

Hi,

I haven't used jira python myself but I can't help thinking that python interprets your "cf[10000]" as a reference to the 10000th element of a list.

From what I can gather customfields should be referenced to as "customfield_10000".

See http://jira-python.readthedocs.org/en/latest/#jirashell and https://developer.atlassian.com/display/JIRADEV/JIRA+REST+API+Example+-+Edit+issues#JIRARESTAPIExample-Editissues-Exampleofupdatingmanyfieldsatthesametime for more info.

Rameez Rahman March 25, 2013

Thanks a lot, Daniel. It was indeed the solution.

This worked

from jira.client import JIRA
jira_options={'server': 'http://localhost:8080'}
jira=JIRA(options=jira_options,basic_auth=('usrname','pwd'))
 
for issue in jira.search_issues(' cf[10000] ~ "Test Value" '):
    issue.update(fields={'customfield_10000': 'New value'})

0 votes
Rameez Rahman March 25, 2013

Thanks a lot, Daniel. That was indeed the solution.

This worked.

from jira.client import JIRA
jira_options={'server': 'http://localhost:8080'}
jira=JIRA(options=jira_options,basic_auth=('rrahman','nike246'))

for issue in jira.search_issues(' cf[10000] ~ "Test Value" '):
	issue.update(fields={'customfield_10000': 'New value'})

TAGS
AUG Leaders

Atlassian Community Events