Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

JIRA Cloud Scriptrunner - Create issue with multi select list not working

David Maurel July 7, 2023

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

2 answers

Suggest an answer

Log in or Sign up to answer
0 votes
Lucy Russon _Adaptavist_ August 23, 2023

Hi David, 

You can set a multi select field using the below syntax:

"customfield_10133": [value: "PARIS"],[value: "BERLIN"]],

I hope this helps! 

Lucy

David Maurel August 23, 2023

Hi,

As I mentionned in the description, I already tried that, and I get the "Specify the value for xxx in an array" error.

David

Lucy Russon _Adaptavist_ August 24, 2023

Hi David,

In your description you've said you were using brackets {value: "<optionValue>"} but you need to use [] instead [value: "PARIS"].

David Maurel August 25, 2023

Hi Lucy,

I did, and I get "Specify the value for xxx in an array" error. I am going to submit a support request from Adaptavist.

David Maurel August 25, 2023

I found the answer. The correct syntax is :

customfield_10133 : [[value: "optionvalue"]], so double square brackets around the set of values.

Thanks.

0 votes
Evgenii
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 7, 2023

Hi, @David Maurel 

I found example, that maybe can help you

"customfield_13222" : [{"add" : {"value" : root_cause_value}}]

In similar question it worked

https://community.atlassian.com/t5/Jira-questions/Updating-Multi-Select-Field/qaq-p/898783

David Maurel July 7, 2023

Hi Evgeniy,

Just tried it, didn't work. Adding the quotes around add and value gets me the  " expecting '}', found ':' " error. If I remove the quotes, I don't get the error, but the fields are not populated with my values.

TAGS
AUG Leaders

Atlassian Community Events