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.