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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Update multi-user list using the API with dynamic number of users

Hey Folks,

at the moment I am facing the problem how to update a multi-user picker field with ScriptRunner. I know the documentation Set User and Group Picker Fields And how to update the field with a specific number of Users.
I need to fill the field with users of an Organization and a group. I already have an array with all the IDs but I am not able to ad it in the body.

In the request body around the inserted String some quotation marks appear which are not needed. Do someone has an Idea how to get rid of them?

Thank you all and have a merry X-mas

Here is some code:

logger.info(visibleForUsers.toString())
StringBuilder sb = new StringBuilder()
String separator = ""
for(accountId in visibleForUsers){ //visibleForUsers contains all the user Ids
sb.append(separator + accountId + "]")
separator = ",[id:";
}

String visibleForUsersAsString = sb.insert(0, "[").append("]").toString()
logger.info(visibleForUsersAsString)
//[[id:5ad9b1d51b0caa2d33f96011],[id:5d53cf6cab24bf0d99416a6f]]




//send Request with all relevant users

result = put("/rest/api/2/issue/" + issueKey)
.header('Content-Type', 'application/json')
.body([
fields:[
customfield_10053 : visibleForUsersAsString
]
]).asString()


// logger.info(result.status.toString())
if(result.status == 200){
return result
}else{
return "failure"
}


 

1 answer

0 votes
Prince Nyeche Community Leader Dec 29, 2020

Hi @Robin Weiß 

Welcome to community, editing a user field on Cloud would require accountId as key with the alphanumeric string as value. So from your code, if you're getting a list of 

[[id:5ad9b1d51b0caa2d33f96011],[id:5d53cf6cab24bf0d99416a6f]]

You might not be able to update such, as it would require it in a dictionary  e.g {"accountId": "5ad9b1d51b0caa2d33f96011"}

So you have to update your code to generate the payload as above before using PUT request on the API.

Hi @Prince Nyeche ,

Thanks for your answer.
I just tried it with curly brackets but the error still occurs.


When I run this code it works perfektly:

result = put("/rest/api/2/issue/" + issueKey)
.header('Content-Type', 'application/json')
.body([
fields:[
customfield_10053: [[id:"5ad9b1d51b0caa2d33f96011"],[id:"5d53cf6cab24bf0d99416a6f"]]
]
]).asString()

But when inserting it as a String what is what I need to have a dynamic Skript it does not not work at all:

def visibleForUsersAsString = "[[id:\"5ad9b1d51b0caa2d33f96011\"],[id:\"5d53cf6cab24bf0d99416a6f\"]]"
result = put("/rest/api/2/issue/" + issueKey)
.header('Content-Type', 'application/json')
.body([
fields:[
customfield_10053: visibleForUsersAsString
]
]).asString()

Maybe you have an idea.

Thanks. 

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
PERMISSIONS LEVEL
Site Admin
TAGS
Community showcase
Published in Marketplace Apps & Integrations

How to log work and track time in Jira when a person is part of multiple teams

  The manager’s daily activities include a list of challenges to reach high levels of efficiency for their teams. Part of these challenges is related to how to deal with the worklog systems sin...

111 views 2 2
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you