You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
Hello,
I am trying to update the Request Participants field via Scriptrunner.
Currently, I am able to retrieve the data but I cannot update it because I lack enough knowledge of how to update the array values of a particular key in a JSON.
I'm writing it using the Scriptrunner console, Groovy.
This is one of my attempts:
def issueKey = 'TEST-1'
def result = get('/rest/api/2/issue/' + issueKey)
.header('Content-Type', 'application/json')
.asObject(Map)
if (result.status == 200){
println(result.body.fields['customfield_10040'])
} else {
return "Failed to find issue: Status: ${result.status} ${result.body}"
}
////////
def place = put('/rest/api/2/issue/'+issueKey)
.header('Content-Type', 'application/json')
.body([fields:['customfield_10040':'62f2882950bd9783f62ce8ef']])
.asString()
////////
if (place.status == 204) {
println("Done")
return 'Success'
} else {
return "${place.status}: ${place.body}"
}
This is the error that I get for the attempt shown above:
"400: {\"errorMessages\":[],\"errors\":{\"customfield_10040\":\"data was not an array\"}}"
So I've fiddled around a bit with various options and the following method has worked for me:
def issueKey = 'ISSUE-KEY'
def Participants = [['accountId':'USER-ID'], ['accountId':'']]
def result = get('/rest/api/2/issue/' + issueKey)
.header('Content-Type', 'application/json')
.asObject(Map)
if (result.status == 200){
//println(result.body.fields['customfield_10040'])
} else {
return "Failed to find issue: Status: ${result.status} ${result.body}"
}
def place = put('/rest/api/2/issue/'+issueKey)
.header('Content-Type', 'application/json')
.body([fields:['customfield_10040':Participants]])
.asString()
if (place.status == 204) {
println("Done")
return 'Success'
} else {
return "${place.status}: ${place.body}"
}
Hope this helps :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.