2013-03-26 67 views
2

我有一個名爲「狀態」與10100的ID的自定義字段是一個選擇列表以「一個」可選值「Two」 「三個」和「四個」。默認值是「One」。更新選擇列表自定義字段 - 吉拉的Python

我在寫一個JIRA python腳本來有條件地更新這個字段的值。如果現有值爲「一個」,則應改爲「兩個」。

這是我的代碼。

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

它給我以下錯誤。

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 

請問您可能會出現什麼問題? 我曾經使用相同的語法編輯類型文本字段的自定義字段,它工作正常。

+0

是價值應該是一個數組出現如下錯誤? – mdoar 2013-03-26 16:28:17

+0

對不起,我沒有得到查詢@mdoar你的意思是選擇列表中的選項的值? 定義自定義字段時,我只將它作爲字符串。 – ramz 2013-03-26 19:21:06

+0

當試圖解決這個問題時,我還觀察到,即使存在ID爲10100的自定義字段(選擇列表),請求「http:// localhost:8080/rest/api/2/customFieldOption/10100」結束了給我一個錯誤。 '{「errorMessages」:[「ID爲'10100'的自定義字段選項不存在」],「errors」:{}}' 奇怪。 – ramz 2013-03-27 11:12:00

回答

3

試試這樣說:

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

或像這樣:

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

我不知道哪一個會工作了你,因爲我從來沒有使用Python的工作,但他們中的一個應該工作。

+0

第一個爲我工作。謝謝! – ramz 2013-04-01 06:34:28

+0

第二個不是有效的python,但第一個也適用於我。 – jalanb 2017-06-30 15:45:16

+0

@jalanb第二個是有效的Python,'{'value','Two'}'評估爲一個集合 – RandomGuy 2017-10-26 01:47:28

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

我有一個多選列表,如果我嘗試更新

response text = {"errorMessages":[],"errors":{"Custom_field":"data was not an array"}}