How to pass an array of multiple choice field values ​​in JSON?

Artem Semenov April 12, 2024

Hi everybody!
I have a code that, when the status changes, transmits field values ​​in Json format to another service, the code works fine, but there is a problem with passing an array of field values, now all values ​​are transmitted as a string. How can I pass the values ​​of a multiple choice field in the format ["1param", "2param", "3param"] ?
I will be grateful for any help


import static
import groovy.json.JsonSlurper
import groovy.json.JsonOutput
import java.util.Base64
import java.util.Base64.Encoder
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.changehistory.ChangeHistoryManager
import helper.RestHelper
import groovy.json.JsonBuilder
def client = new RESTClient(url)
//Change to match your username/password
def authBasic = Base64.getEncoder().encodeToString(("login"+":"+"pass").getBytes());
IssueManager im = ComponentAccessor.getIssueManager()
Issue currentIssue = im.getIssueObject(event.getIssue().getKey())
ChangeHistoryManager chm = ComponentAccessor.getChangeHistoryManager()
def lastChange = chm.getChangeHistories(currentIssue)[-1].getChangeItems()
if ((lastChange.field[0].equals("status")) || (lastChange.field[1].equals("status")))  {    
        String oldStatus = lastChange.oldstring[0]
        String newStatus = lastChange.newstring[0]
    if (!newStatus.equals(oldStatus)) {
        Map jsonObj = [
            "key"         : currentIssue.getKey(),
            "issueType"   : currentIssue.getIssueType().name,
            "status"   : newStatus,
            "Prichina" : currentIssue.getCustomFieldValue(16308).toString(),
            "Shtat" : currentIssue.getCustomFieldValue(19700).toString(),
            "Konkurent" : currentIssue.getCustomFieldValue(19701).toString()
HttpResponseDecorator response = (HttpResponseDecorator) "",
      contentType: JSON,
      body: jsonObj,
  //headers: [Accept: 'application/json',Authorization:"Basic ${authBasic}"]);
    headers: [Accept: 'application/json']);
    log.error("Status: " + response.status)
    log.warn("requestBody: ${jsonObj}")
    if ( {
      log.error("Content Type: " + response.contentType)
      log.error("Headers: " + response.getAllHeaders())
      log.error("Body:\n" + JsonOutput.prettyPrint(JsonOutput.toJson(
      //log.error("requestBody: ${jsonObj}")
catch(HttpResponseException e){
    log.error e.getResponse().getData()
    //log.error("requestBody: ${jsonObj}")

2 answers

0 votes
Artem Semenov April 17, 2024

I managed to solve this problem using JSON array:

def multiSelectField = customFieldManager.getCustomFieldObject("customfield_19700")
def shtat = currentIssue.getCustomFieldValue(multiSelectField) as List
JSONArray jsonArray_shtat = new JSONArray()
    if (shtat != null) {  
jsonArray_shtat = [
0 votes
Matt Parks
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 15, 2024

I can't tell exactly where you're trying to set multiple values to the same field in your API call, but I found a post that had code that seemed to work for some users:


Below seems to be the basics of what they included:



{ "customfield_11201": [{"value": "Disclosure"},{"value": "SecondValue"},{"value": "ThirdValue"}]


Artem Semenov April 17, 2024

Thank you, this is not exactly what I needed, I managed to solve the problem using JSONArray.

Suggest an answer

Log in or Sign up to answer