It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Update custom field using Jira Python

Rameez Rahman Mar 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

3 votes
Answer accepted
Daniel Prahl Mar 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 Mar 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 Mar 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'})

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Next-gen

Introducing subtasks for breaking down work in next-gen projects

Teams break work down in order to help simplify complex tasks. This is often done iteratively, with tasks being broken down into smaller tasks and so on until the work is accurately captured in well-...

1,140 views 13 16
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you