Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Create an issue with multiselect customefield

Deleted user April 7, 2021

Hi, I'm trying to create a new issue and I have to inform the mandatory customfields. When I try to infrom the multiselect custome field appear this error message: 

{errorMessages=[], errors={Compañía=Specify the value for Compañía in an array}

In the next link (Jira REST API examples (atlassian.com) I found that the correct form to inform a multiselect field is "customfield_10008": [ {"value": "red" }, {"value": "blue" }, {"value": "green" }]  but when I try the error message disapear and create the new issue but the customfield is without value. My multiselect field are Compañía, Aplicacion and Proveedor.

image.png

I don´t know how is the correct form to inform this type of fields.

Thanks!

The part of the code that I use to create a issue is:

//Función de Crear
def miFuncionCrear(String projectKey, def idTipoTarea, def Area, def Peticionario, def Ano, def Compania, def Aplicacion, def Proveedor) {
post('/rest/api/2/issue')
.header('Content-Type', 'application/json')
.body([
fields: [
project : [
key: projectKey
],
issuetype: [
id: idTipoTarea
],
summary : "Requerimiento creado mediante script",

customfield_10064:[value:Area], //Area
customfield_10068:Peticionario, //Peticionario
customfield_10063:[value:Ano], //Año
customfield_10139:[{value:Compania}], //Compañia
customfield_10140:[{value:Aplicacion}], //Aplicacion
customfield_10141:[{value:Proveedor}] //Proveedor

]
])
.asObject(Map)
}

This is my complete code:

String miQuery
String miJQL
def issueKey
String claveProyecto
def taskTypeId


//Función de busqueda
def miFuncionSearch(String buscar) {
Map<String, Object> searchResult = get('/rest/api/2/search')
.queryString('jql', buscar)
.queryString('fields', 'project')
.asObject(Map)
.body
def issuesSearch = (List<Map<String, Object>>) searchResult.issues
String issuekeySearch=issuesSearch.key
}

//Función de Crear
def miFuncionCrear(String projectKey, def idTipoTarea, def Area, def Peticionario, def Ano, def Compania, def Aplicacion, def Proveedor) {
post('/rest/api/2/issue')
.header('Content-Type', 'application/json')
.body([
fields: [
project : [
key: projectKey
],
issuetype: [
id: idTipoTarea
],
summary : "Requerimiento creado mediante script",

customfield_10064:[value:Area], //Area
customfield_10068:Peticionario, //Peticionario
customfield_10063:[value:Ano], //Año
customfield_10139:[{value:Compania}], //Compañia
customfield_10140:[{value:Aplicacion}], //Aplicacion
customfield_10141:[{value:Proveedor}] //Proveedor

]
])
.asObject(Map)
}


//Función de lincar
def miFuncionLink(String enlace, def outIssue, def inIssue) {
post('/rest/api/2/issueLink')
.header('Content-Type', 'application/json')
.body([
type: [ name: enlace ],
outwardIssue: [ key: outIssue ], // This is the issue that the link 'starts' at
inwardIssue: [ key: inIssue ] // You'll need to specify an issue ID or key here
])
.asString()
}

//Buscamos la tarea de la que queremos recuperar los valores, en este caso se la indicamos nosotros pero deberia buscar directamente en la tarea que se acaba de crear
// The issue key Se especifica el ID de la tarea que queremos
issueKey = 'GDP-7'
// Fetch the issue object from the key
def issue = get("/rest/api/2/issue/${issueKey}")
.header('Content-Type', 'application/json')
.asObject(Map)
.body
// Get all the fields from the issue as a Map
def fields = issue.fields as Map


final String issueTypeName = 'Requerimiento'


def taskType = get('/rest/api/2/issuetype')
.asObject(List)
.body
.find { (it as Map).name == issueTypeName } as Map


taskTypeId = taskType.id


//Especificamos el customfield id del que queremos recuperar el valor y lo guardamos (Area)
// Get the Custom field to get the option value from Campo
def customField1 = get("/rest/api/2/field")
.asObject(List)
.body
.find {
(it as Map).id == 'customfield_10064'
} as Map
def Area = fields[customField1.id].value;
//Escribimos en el log el valor recuperado
logger.info("Area ${Area}")


//Especificamos el customfield id del que queremos recuperar el valor y lo guardamos (Peticionario)
// Get the Custom field to get the option value from Campo
def customField2 = get("/rest/api/2/field")
.asObject(List)
.body
.find {
(it as Map).id == 'customfield_10068'
} as Map
def Peticionario = fields[customField2.id]; //En este caso no ponemos el .value sino que ponemos .toString() porque se trata de un text box
//Escribimos en el log el valor recuperado
logger.info("Peticionario ${Peticionario}")


//Especificamos el customfield id del que queremos recuperar el valor y lo guardamos (Ano)
// Get the Custom field to get the option value from Campo
def customField3 = get("/rest/api/2/field")
.asObject(List)
.body
.find {
(it as Map).id == 'customfield_10063'
} as Map
def Ano = fields[customField3.id].value;
//Escribimos en el log el valor recuperado
logger.info("Ano ${Ano}")


//Especificamos el customfield id del que queremos recuperar el valor y lo guardamos (Compania)
// Get the Custom field to get the option value from Campo
def customField4 = get("/rest/api/2/field")
.asObject(List)
.body
.find {
(it as Map).id == 'customfield_10139'
} as Map
def Compania = fields[customField4.id].value;
//Escribimos en el log el valor recuperado
logger.info("Compania ${Compania}")


//Especificamos el customfield id del que queremos recuperar el valor y lo guardamos (Aplicacion)
// Get the Custom field to get the option value from Campo
def customField5 = get("/rest/api/2/field")
.asObject(List)
.body
.find {
(it as Map).id == 'customfield_10140'
} as Map
def Aplicacion = fields[customField5.id].value;
//Escribimos en el log el valor recuperado
logger.info("Aplicacion ${Aplicacion}")


//Especificamos el customfield id del que queremos recuperar el valor y lo guardamos (Proveedor)
// Get the Custom field to get the option value from Campo
def customField6 = get("/rest/api/2/field")
.asObject(List)
.body
.find {
(it as Map).id == 'customfield_10141'
} as Map
def Proveedor = fields[customField6.id].value;
//Escribimos en el log el valor recuperado
logger.info("Proveedor ${Proveedor}")


//String[] arrStr2 = ['BSAS']

def createIssue= miFuncionCrear('GDP', taskTypeId, Area, Peticionario, Ano, Compania, Aplicacion, Proveedor)
def createdIssueKey = createIssue.body.key as String
logger.info("The ${createdIssueKey} issue was created")


// Return the option values
return "The values of the requerimiento are: Area ${Area}, Peticionario ${Peticionario}, Ano ${Ano}, Compania ${Compania}, Aplicacion ${Aplicacion}, Proveedor ${Proveedor}"

1 answer

0 votes
Trudy Claspill
Community Champion
April 23, 2021

For each of the three fields, are the values you provided in the code values that can be selected in those fields through the UI?

customfield_10139:[{value:Compania}], //Compañia
customfield_10140:[{value:Aplicacion}], //Aplicacion
customfield_10141:[{value:Proveedor}] //Proveedor

 

For the Compania field, is "Compania" a value you can select in that field in the UI?

The values you provide in your code must be values that are selectable for the specified field.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events