Hi,
I've managed to write a script using API Post to create an issue with all the required fields, but I have a problem with multi select list fields. Whatever I try, these fields remain empty. Can anyone tell me what is wrong with this ?
Here's my script :
def projectKey = 'KESD'
def projectId = get("/rest/api/2/project/${projectKey}").asObject(Map).body.id
String email_resp = "myemail@mydomain.com"
String email_rapp = "hisemail@mydomain.com"
def url_resp = "/rest/api/2/user/picker?query=${email_resp}"
def url_rapp = "/rest/api/2/user/picker?query=${email_rapp}"
def response_resp = get(url_resp).header('Content-Type', 'application/json').asObject(Map)
def accountId_resp = response_resp.body.users.accountId[0]
def response_rapp = get(url_rapp).header('Content-Type', 'application/json').asObject(Map)
def accountId_rapp = response_rapp.body.users.accountId[0]
def ticketType = get("/rest/api/2/issuetype/project?projectId=${projectId}").asObject(List).body.find { it['name'] == 'ServiceRequest' }['id']
post('/rest/api/2/issue')
.header('Content-Type', 'application/json')
.body(
[
fields: [
summary : 'The issue summary',
description: """Hello,
This is the issue description.
Regards,
Me""",
project : [key: projectKey],
issuetype : [id: ticketType],
duedate : "2023-07-17",
reporter : [id: accountId_rapp],
assignee : [id: accountId_resp],
customfield_10138 : "DRIVER",
customfield_10142 : "HOTELS",
customfield_10133 : [{name: 'PARIS'}],
customfield_10143 : [id: "10440"],
customfield_10445 : [{name: 'No Hardware'}],
security : [name:'DSI']
]
])
.asString().body
Everything works fine, except for the customfield_10133 and 10445, which are multi-select list fields with only one value. I tried {id: "<optionId>"}, {name: "<optionValue>"}, {value: "<optionValue>"}, didn't work. I tried with quotes on "id", "name", and "value", I got the " expecting '}', found ':' " error. And if I remove the {} brackets, I get the "value must be in a table" error.
I cannot find the exact syntax for that, all examples on the internet point to other ways to do it with lots of java methods, or Server/Data Center compatible methods.
Thanks for your help.
David