Update custom field using Jira Python

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

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.

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

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
Community showcase
Posted Friday in United States

Confluence Security Advisory

Good morning Members, Not sure if you are aware. Please read the following: https://www.icloud.com/keynote/0RyJ4VEdNUpjDpGfMhfZx9fEg#Confluence_Security_Advisor More details: https://co...

43 views 1 0
View post

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