Error: "data was not array" when updating custom field config values

alexmears August 29, 2018

I have a custom field that has multiple options.

I am trying to update Option 1 via a script using ScriptRunner

put("/rest/api/2/issue/${issueKey}")
.header("Content-Type", "application/json")
.body([
fields:[
"customfield_10066": [
"value": "Option1"
]
]
])
.asString()

Problem: the above script returns an error:

2018-08-30 03:54:35.081 WARN - PUT request to /rest/api/2/issue/OP-35 returned an error code: status: 400 - Bad Request
body: {"errorMessages":[],"errors":{"Flag":"data was not an array"}}

where "Flag" is the name of customfield_10066

Note: I have tried wrapping the value change as follows:

[{"value": "Option1"}]

but this returns an equally fatal error:

Script1.groovy: 47: expecting '}', found ':' @ line 47, column 34.
                           [{"value": "Option1"}]
                                    ^

 

2 answers

2 accepted

5 votes
Answer accepted
Mark Markov
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.
August 30, 2018

Hello @alexmears

Try 

put("/rest/api/2/issue/${issueKey}")
.header("Content-Type", "application/json")
.body([
fields:[
"customfield_10066": "Option1"
]
])
.asString()

 or

put("/rest/api/2/issue/${issueKey}")
.header("Content-Type", "application/json")
.body([
fields:[
"customfield_10066": [[value: "Option1"]]
]
])
.asString()
alexmears September 4, 2018

Your second option worked!! Thank you very much.

Eshwar Iyer February 10, 2022

The second option worked for me too. Thanks !!

2 votes
Answer accepted
Kristian Walker _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 4, 2018

Hi Alex,

Are you trying to update the 'Flagged' field which is provided by JIra Software out of the box?

If this is the case I have an example script console script which shows how to do this which is located here.

You will be able to use this script to see how to set the flagged field and to see an example of the syntax required for specifying an array value.

If this response has answered your question can you please mark it as accepted so that other users can see it is correct when searching for similar answers.

Regards,

Kristian

alexmears September 4, 2018

Your solution was the same as the 2nd option above. It worked! I appreciate the inline comments in the code, because it explained that I need to "initiate the array".

Kristian Walker _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 5, 2018

Hi Alex,

I am glad that we were able to help resolve your issue.

Could you please accept both answers in order to mark them both as correct for users searching for the same question.

Regards,

Kristian

Suggest an answer

Log in or Sign up to answer