Update issue status in Jira by status name using transitions

Problem:

I have imported issues from one instance into a project in another instance. The issue’s status is always ‘Open’ instead of the original status in the old issue.

Expectation:

I will need to update the status of the issue from ‘open’ to ‘something’. This is something i have to do it programmatically ( through plugin or REST APIs). NOT from Jira administration user interface.’.

Solution:

Transition issue from one status to another using transition id.

How did I achieve:

First I have retrieved all possible transitions for the issue (to which, the status to be updated) using REST API.

The rest api call will look like this:

URL:  https://localhost:8080/rest/api/2/issue/TESTISSUE-1/transitions 

Result json:
 {
  "expand": "transitions",
  "transitions": [
    {
      "id": "91",
      "name": "Created",
      "to": {
        "self": "https://localhost:8080/rest/api/2/status/13515",
        "description": "Completed",
        "iconUrl": "https://localhost:8080/images/icons/statuses/xyz.png",
        "name": "Completed",
        "id": "13515",
        "statusCategory": {
          "self": "https://localhost:8080/rest/api/2/statuscategory/1",
          "id": 1,
          "key": "undefined",
          "colorName": "medium-gray",
          "name": "No Category"
        }
      }
    }
  ]
}

From the above json, “to” denotes the ‘ to status’ .The to object has everything we need to check against the status name we have.

The ‘to’ has the following important fields:

  1.  “name”: “Completed”,
  2. “id”: “13515”,

We will use the name to check against what we have ‘status name’, if it matches, then ‘ “id”: “91”,’ is our transition id.

Once we get the transition id, then we can call rest api again to transition the issue using transition id.

It is done. now if the passed status is matched with the ‘to’ status name, then the issue will be transitioned to expected status.

Leave a Reply

Your email address will not be published. Required fields are marked *