Hi there
I'm trying to auto update a custom field and a system field during transition by using ScriptRunner in JIRA Cloud.
I'm want to use POST method. Take note that I've tried with actual value but keep getting error. I guess my body isn't correct. I'm new to Groovy. Kindly assist.
Please find below code.
// Specify here the issue key for the issue to transition
def issueKey = '<issue name>'
//check if issue is assigned
def result = get('/rest/api/2/issue/' + issueKey + '?fields=assignee')
.header('Content-Type', 'application/json')
.asObject(Map)
if (result.body.fields.assignee.accountId != null)
{
// The ID of the workflow transition to execute.
// Note - The transition ID must represent a valid transition for the workflow that the issue uses.
def transitionID = '<transitionID>'
// The rest call to transition the issue
def transitionIssue = post("/rest/api/2/issue/${issueKey}/transitions")
.header("Content-Type", "application/json")
.body( [
fields: [
[
"customfield_10050": '5'
],
[
"summary": 'Task name from script'
]
]
,
transition: [id: transitionID]
])
.asObject(Map)
// Check if the issue was transitioned correctly
if (transitionIssue.status == 204) {
return "The ${issueKey} issue was transitioned to the status with the id of ${transitionID}"
} else {
return "The escalation service failed to transition the ${issueKey}issue. ${transitionIssue.status}: ${transitionIssue.body}"
}
}