Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,364,761
Community Members
 
Community Events
168
Community Groups

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

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

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

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. 

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

Atlassian Community Events