Insert value into customfield of type "multi checkbox" using jira-python API

Karen Clark April 28, 2014

I am using jira-python API v0.13. (Snippets below exclude jira client set-up scaffolding for brevity.)

I need to update a multi-checkbox field which has NO VALUE currently, to make one of the boxes "checked".

Multi-checkbox field name = Flags

Values = Customer, Partner, Other

I've initalized the connection with JIRA successfully. I can get data from this multi-checkbox field for a record that HAS values for this multi-checkbox:

>>> i = jira.issue('ABC-123')
>>> f = i.fields.customfield_10060
>>> [v.value for v in reversed(f)]
[u'Customer',u'Partner']

However, when I am unable to update the field to insert a new value. Specifically, I am attempting to push values into a record that has NO VALUES set for the checkbox yet (don't know if that's the problem or not, since I can't insert values for one that has one or more values, either!)

This doesn't work:

>>> i = jira.issue('ABC-155')
>>> i.update(fields={'customfield_10060': {'value': 'Customer'}})
error is jira.exceptions.JIRAError: HTTP 400: "{u'Flags': u'data was not an array'}"

Neither does this:

>>> i = jira.issue('ABC-155')
>>> i.update(fields={'customfield_10060': ['value', 'Customer']})
error is jira.exceptions.JIRAError: HTTP 400: "{u'Flags': u'expected Object'}"

Comments / suggestions appreciated.

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

2 votes
Answer accepted
Boris Georgiev _Appfire_
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.
April 28, 2014

You should pass array of objects as specified here - https://developer.atlassian.com/display/JIRADEV/JIRA+REST+API+Example+-+Create+Issue#JIRARESTAPIExample-CreateIssue-MultiSelect

i.update(fields={'customfield_10060': [{'value': 'Customer'}]})

Karen Clark April 29, 2014

Perfect!

Thanks so much, Boris. That link to the dev wiki is very helpful indeed!

Gabriel Almeida June 16, 2016

@Boris Georgiev [Botron]

The problem with this approach is that the update will overwrite previous values.

Assuming we have a multiple select checkbox custom_field:

[ ] option1 
[ ] option2
[x] option3

after update 

i.update(fields={'customfield_10060': [{'value': 'option1'}]})

field will be

[x] option1 
[ ] option2
[ ] option3

 

The option 3 is gone.
Do you know how can we adapt the update method to just "add" (select) another option, without erasing the previously selected options ??? result in this case should be 


[x] option1 
[ ] option2
[x] option3


Boris Georgiev _Appfire_
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.
June 16, 2016

Try getting the value of the field first, then make your updates and last - pass the value back to JIRA for update

Gabriel Almeida June 16, 2016

@Boris Georgiev [Botron], I am almost there...

for issue in issues:
	print "hi all, i am here"
	selected_values = issue.fields.customfield_13336
	values = "["
	for value in selected_values:
		values += "{{'value': '{0}'}},".format(value)
	values = values[:-1]
	values += "]"
	#issue.update(fields={'customfield_13336':[{'value':hostOption} ,{'value':targetOption}]})
	issue.update(fields={'customfield_13336':values})

The error:

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

 

I basically get all values and store in a string, then I try to provide over issue.update(xxx).

Do you have an idea how I can compose a variable array of objects with the values to be provided to issue.update?

Mikhail Sheverdyaev November 6, 2017

@Gabriel Almeida2

This should work, applying to your example here :

...
 selected_values = issue.fields.customfield_13336
 values = []
for value in selected_values: values += [{'value':str(value)}] issue.update(fields={'customfield_13336':values})
Dimitris Armenatzoglou January 23, 2018

@Mikhail Sheverdyaev Thank you! 

TAGS
AUG Leaders

Atlassian Community Events