Setting value of an array custom customfield

Marc Vilella July 14, 2014

Hi, I have a custom customfield that is an array:

MultipleField extends AbstractCustomFieldType<Collection<String>, String>

I have to insert data with this field via REST api, and when I send this json:

{"fields": {"summary": "asdf","issuetype": {
            "id": "10014"
        },
        "project": {
            "id": "10000"
        },
        "customfield_10400": ["asdf","asdfdaogaeogeryghoe"]
    }
}

it says to me that it expects an string as a value of the custom field...

{"errorMessages":[],"errors":{"customfield_10400":"Operation value must be a string"}}

How I can set a list of Strings as the value of the custom field via rest api? It is not possible to log and fill it via UI.

Thanks!

4 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Richard Scott October 24, 2016

I had some issues with a string custom field when using the Rest API to create a ticket.. getting the same operation value must be a string error.  I played with formatting the request Json.  In my case, it was a string field that JIRA converts to a hyperlink automatically.

Simply pop the following into the Json body for issue post:

"customfield_14401": "some string that you want to update on your ticket"

On ticket update, this will work:

{"update":{
"customfield_14401":[{"set":"some string that you want to update on your ticket"}]
}
}

Johnny Chow June 29, 2017

If I want to set customfield_14401 to ["string1", "string2"], what is the Json body like please?

Like Erik Buchholz likes this
0 votes
benmingli July 11, 2017

I managed to insert only 1 string by the following,

 

"customfield_18240": "{\"name\":\"aaaaaaaaaaaaaaaa\", \"name\":\"test case bbbbbbbbbb\"}"

 

 

Sabari Nathan April 6, 2018

Hi. Do you know how pass more than one value.

Sabari Nathan April 9, 2018

At last I found how to pass more than one value for multiselect custom field,

"customfield_18240": "{\"name\":\"aaaaaaaaaaaaaaaa\", \"name\":\"test case bbbbbbbbbb\"}#|#{\"name\":\"bbbbbbbbb\", \"name\":\"test case cccccccccc\"}"

BarbaraG May 9, 2018

And how to take the values from the parent?

0 votes
Marc Vilella July 29, 2014

I finally passed a json object as an string and parsed inside jira.

Thank you anyway

Johnny Chow June 26, 2017

How did you do that, can you tell me please?

Like # people like this
0 votes
Marten Kreienbrock
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.
July 14, 2014

From what I see, you send a JSON array to the API, which requires a string. Have you tried JSON.stringify(["asdf","asdfd..oe]) to turn your array in a valid string?

Marc Vilella July 20, 2014

That is not the problem, the json is valid, it's an array and it follows JSON standards, I want to know why it isn't accepted by jira...

The main problem is that it says that customfields only accept Strings, then why labels customfield accepts so?

Marten Kreienbrock
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.
July 20, 2014

I did not mean to say your JSON would be invalid, but Jira is sometimes quite tricky in its demanded types. So I suggested you transform your JSON into a string by using JSON.stringify. This should provide you with a string for the API, which will turn this string back to a JSON object. Don't ask me why one would have to do this unnecessary step, but in some cases Jira wants exactly these kind of strings to be send. Just give it a try, it might just work.

Marc Vilella July 21, 2014

I'm using the rest api browser plugin. No need to stringify.see:

rest api plugin

I need to know the correct format to upload array values and be parsed so. I asume there is an special tratment for that different from JSON standards, that's what I'm asking here.

OR

Maybe my custom field module configuration is not correct and I need to set something especial in order to accept arrays:

{

    "id": "customfield_11000",

    "name": "testField",

    "custom": true,

    "orderable": true,

    "navigable": true,

    "searchable": true,

    "clauseNames": [

      "cf[11000]",

      "testField"

    ],

    "schema": {

      "type": "array",

      "items": "string",

      "custom": "org.test.rest-plugin:multiple-field",

      "customId": 11000

    }

  },

Marten Kreienbrock
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.
July 21, 2014

As far as I know (and I tested your format with an array of string field on our system) your syntax is correct and should work just fine. However, it seems Jira had some issues with setting array fields and the only way to work around it was to only send a single value at a time. So instead of placing the whole array when you create the issue via rest, you only could place a single value and set the rest later.

An other recomendation from me so see if it would work at all would be to add your customfield to the default screen of your jira, so you can edit it in the create dialog. This way you could add multiple values and then look at the actual request send by jira to it's rest api by using firebug or something similar. By doing so you should get a valid request body, which you could later implement for your own purpose.

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events