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

Edit Multi User Picker FIeld

Cooper Latham April 24, 2023

Hi community, 

I am using Scriptrunner Cloud to attempt to retrieve the members of a Jira group (group1), and write those users to a multi user picker custom field.

  • I have a call to retrieve the group members' account IDs (working)
  • Using collect to format the list of account IDs to make it API call ready (?)
  • The edit/put call is working when values are manually typed in (working)
  • Error when executing the script -- "errors":{"customfield_xxxxx":"expected Object"}}
  • I suspect that my issue is with how I am formatting the list of account IDs, but I do not know of any alternatives.

---

def gusers = get("/rest/api/3/group/member?groupname=group1")
.header("Content-Type", "application/json")
.asObject(Map)
def accountdetails = gusers.body.values as List<Map>
def accountids = accountdetails.accountId
def modaccountids = accountids.collect{'["id":' + '"' + it + '"]'}

print(modaccountids)

//api call
put("/rest/api/3/issue/ABC-123")
.header("Content-Type", "application/json")
.queryString("overrideScreenSecurity", Boolean.TRUE)
.body([
"fields": [
"customfield_xxxxx": [
modaccountids
]
]
])
.asString()

 

Any help would be greatly appreciated!

1 answer

1 accepted

2 votes
Answer accepted
Cooper Latham April 25, 2023

Hi community, 

After a few more cycles, I was able to resolve this issue. In my original post, I thought my issue was related to the way formatting the list of account IDs, and that did turn out to indeed be the issue. Here is how I resolved it...

 

Original: def modaccountids = accountids.collect{'["id":' + '"' + it + '"]'}

Updated: def idList = accountids.collect { item -> ["id": item] } 

 

Hopefully this can help the community at some point in the future. Cheers!

Duc Anh Le November 13, 2023

Hi @Cooper Latham ,
With mine issue, it turned out 

body: {"errorMessages":[],"errors":{"customfield_10246":"data was not an array"}}

 Would you please mind taking a look at my script? I still have not figured error cause. I am very appreciate with your help.
Here below is the script using in Post-function:

def issueKey = issue.key

def result = put("/rest/api/2/issue/${issueKey}")
.header('Content-Type', 'application/json')
.body([
fields: [
"customfield_10246": [
"id": "61812ae5062f4c006918316e"
]
]
])
.asString()

Duc Anh Le November 13, 2023

My mistake, I just need to put accountId object between the "[ ]".

Like Cooper Latham likes this
Cooper Latham November 15, 2023

Glad I could help :) lol

Like Duc Anh Le likes this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events