// Check if ticket is assigned to a user
// -- If not, check that the user has the assignable user permission
// ----- If they do, assign it to the current user
if (issue.fields.assignee != null) {//Set assignee here,
def issueKey = 'AAA-111111'def result = get('/rest/api/2/issue/' + issueKey + '?fields=assignee') .header('Content-Type', 'application/json') .asObject(Map)if (result.status == 200){ if (result.body.fields['assignee'] == null) { def put = put('/rest/api/2/issue/' + issueKey) .header('Content-Type', 'application/json') .body([ fields:[ assignee: [ id: 'admin' ] ] ]) .asString() if (put.status == 204) { return 'Success' } else { return "${put.status}: ${put.body}" } }} else { return "Failed to find issue: Status: ${result.status} ${result.body}"}
@Nir can I get a brief explanation of the code?
Sure,
def result = get('/rest/api/2/issue/' + issueKey + '?fields=assignee')
this get only the "assignee" field data (no need to get all data if all you want is the assignee)
inside you got "if" statement, status 200 says "success"
so if success to get the assignee data of the issue, check if it null
if (result.body.fields['assignee'] == null)
if it is null, put (update) the assignee that you want (in my example i set 'admin'), you change the assignee to who ever you want.
@Nir Haimov if I want the user who executed the transition to be set as the assignee is that the current user? How would I do so?
It looks like you're new here. Sign in or register to get started.