Are you in the loop? Keep up with the latest by making sure you're subscribed to Community Announcements. Just click Watch and select Articles.

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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

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

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

Hi David, 

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

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

I hope this helps! 

Lucy

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

Hi David,

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

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.

I found the answer. The correct syntax is :

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

Thanks.

0 votes
Evgeniy
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.
Jul 07, 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

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