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

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

2 votes
Accepted answer

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

Perfect!

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

@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


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

@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?

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

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted yesterday in United States

Topic Tuesday, now on Thursday! :-P

Happy Thursday everyone! This is usually a Tuesday thing but I've been crazy busy.  I finally had a moment to breath and so here we are. Atlassian has several tools and features to help users ...

12 views 0 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