Auto update custom field and system field during transition by using ScriptRunner in JIRA Cloud

Yugeswaran Vasudevon September 20, 2022

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

 

2 answers

0 votes
Yugeswaran Vasudevon September 21, 2022

I've managed to solve this. I'm unable to use update custom fields in the transition as the fields were not available. I was unable to get the fields although I tried to change the screen types in workflow transition. 

So I managed to use PUT method to update fields.

0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 20, 2022

See https://library.adaptavist.com/entity/calculate-custom-field-on-issue-update - adjusting a system field is just a case of using its name directly as you already are. 

Yugeswaran Vasudevon September 20, 2022

Hi Nic.. Thanks for the suggestion.. I'm trying to update the fields by using POST function when doing transition.. 

Please look at below script.

Script.png

I got below error. Please assist.

error.png

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events