Is it possible to change an issue status using Script runner Cloud

Mohammed-Amine Rouh January 14, 2019

Hi,

I am trying to change an issue Status (To Do, In Progress or Done), using the following simple method

// Code 1

def result = put("/rest/api/2/issue/${parentEpicKey}")
.header('Content-Type', 'application/json')
.body([
fields: [
status: "[self:https://domain.com.atlassian.net/rest/api/2/status/3, description:This issue is being actively worked on at the moment by the assignee., iconUrl:https://domain.com.atlassian.net/images/icons/statuses/inprogress.png, name:In Progress, id:3, statusCategory:[self:https://domain.com.atlassian.net/rest/api/2/statuscategory/4, id:4, key:indeterminate, colorName:yellow, name:In Progress]]"
]
])
.asString()
I get the following error : 
{"errorMessages":[],"errors":{"Status":"Field 'Status' cannot be set. It is not on the appropriate screen, or unknown."}}
       |                    false

 

I have already extracted the value of Status for tickets with this :

//Code 2
def fields = get("/rest/api/2/field")
.asObject(List)
.body
.findAll { (it as Map) } as List<Map>

def statusField = fields.find { it.name == 'Status' }
logger.info("statusField : ${statusField}")

which prints the values I am trying to assign to Status in Code 1.

 

Does anyone have any idea please on what I am missing ?

Thank you

 

2 answers

1 accepted

5 votes
Answer accepted
Nir Haimov
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 14, 2019

Hi,

Yes you can, use:

POST /rest/api/3/issue/{issueIdOrKey}/transitions

in your body you need to send:

"transition": {
    "id": "5"
  }

 

Read this:

https://developer.atlassian.com/cloud/jira/platform/rest/v3/?utm_source=%2Fcloud%2Fjira%2Fplatform%2Frest&utm_medium=302#api-api-3-issue-issueIdOrKey-transitions-post

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.
January 14, 2019

Status is not a field you can just edit, it is an indication of where an issue is in the process.  To change it, you must use a transition to move the issue through it.

Like HUI LI likes this
Mohammed-Amine Rouh January 14, 2019

Thank you I wasn't aware of that, however the transition is Empty

 

// Get available transitions
def transitions = get("/rest/api/3/issue/${parentEpicKey}/transitions")
.asObject(Map)
.body
.issues as List<Map>
logger.info("transitions: ${transitions}") // Returns Null

// To find the Transition ID, is there any way to not start guessing
// Error "Transition id '2' is not valid for this issue
def result2 = post("/rest/api/3/issue/${parentEpicKey}/transitions")
.header('Content-Type', 'application/json')
.body([
transition: [
"id": "3"
]
])
.asString()
Mohammed-Amine Rouh January 14, 2019

Thank you, I wasn't aware of Transitions however the value seems to be empty to know which ID to send.

// Get available transitions
// Returns Null

def transitions = get("/rest/api/3/issue/${parentEpicKey}/transitions")
.asObject(Map)
.body
.issues as List<Map>
logger.info("transitions: ${transitions}")

// Tried few IDs from the status or just as a guess nothing seems to be working
//"Transition id '3' is not valid for this issue
def result2 = post("/rest/api/3/issue/${parentEpicKey}/transitions")
.header('Content-Type', 'application/json')
.body([
transition: [
"id": "3"
]
])
.asString()
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.
January 14, 2019

You need to use a transition that exists and your user has permission to use.  This depends on what status the issue is currently in and what your workflow says.

Amine-Rouh January 14, 2019

Worked like a charm, Thank you @Nir Haimov and @Nic Brough -Adaptavist- for the support, Appreciated 

Gustavo De Marco August 20, 2019

hey can u help me u do u do that ?

1 vote
Frank Sessler
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 1, 2022

@Mohammed-Amine Rouh
I suppose you have found the answer, as this thread is more than 3 years old. Anyway for others (like me): you may find the transition ID in the workflow configuration, text mode.

Transition_ID.png

Suggest an answer

Log in or Sign up to answer