4

I have a custom field named "Status" with an id of 10100 which is a select list with optional values of "One", "Two", "Three" and "Four". Default value is "One".

I am writing a JIRA python script to update the value of this field conditionally. Say if the existing value is "One", it should be changed to "Two".

This is my code.

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[10100] = "One" '):
    issue.update(fields={'customfield_10100': 'Two'})

It's giving me the following error.

Traceback (most recent call last):
  File "test.py", line 11, in <module>
    issue.update(fields={'customfield_10100': 'Two'})
  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

Could you please tell me what might be wrong? I had used the same syntax for editing a custom field of type text field and it had worked fine.

3
  • Is the value supposed to be an array? Commented Mar 26, 2013 at 16:28
  • Sorry, I didnt get the query @mdoar You mean the values for the options in the select list ? While defining the custom field I gave it as strings only. Commented Mar 26, 2013 at 19:21
  • While trying to solve this issue I also observed that even though the custom field (select list) with the id 10100 exists, the request http://localhost:8080/rest/api/2/customFieldOption/10100 ended up in giving me an error. {"errorMessages":["A custom field option with id '10100' does not exist"],"errors":{}} Weird. Commented Mar 27, 2013 at 11:12

1 Answer 1

5

Try it like this:

issue.update(fields={'customfield_10100': {'value':'Two'}})

or like this:

issue.update(fields={'customfield_10100': {'value','Two'}})

I am not sure which one will work out for you because I never worked with Python, but one of them should work.

Sign up to request clarification or add additional context in comments.

3 Comments

The second one is not valid python, but the first one worked for me too.
@jalanb The second one is valid Python, {'value', 'Two'} evaluates to a set
Yes, of course it is valid. Must've been off my meds that day.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.