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

How to update Request Participants via Scriptrunner?

Emil Khairov April 13, 2023

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\"}}"

 

1 answer

1 accepted

3 votes
Answer accepted
Emil Khairov April 13, 2023

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 :) 

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
TAGS
AUG Leaders

Atlassian Community Events