How to get status value via javascript

Raju KC
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 25, 2013

Below js does not work for me in v5.1

AJS.$("#status").val()

Any help!!!!!

2 answers

1 accepted

1 vote
Answer accepted
Mizan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 25, 2013

You can get the status of an issue through REST api

/rest/api/2/issue/{issueIdOrKey}

You will get a json output which contains the status value , u can process it to get the status .

EDIT : Try below javascript

<script type="text/javascript">

function getCurrentStatus()
{
var statusname;
     AJS.$.ajax({
        url: "/rest/api/2/issue/XYZ-123",
        type: 'get',
        dataType: 'json',
        async: false,
        success: function(data) {
            statusname = data.fields.status.name;
        } 
     });
     return statusname;
}

alert("Status : " +getCurrentStatus())
</script>

Ryan Aherne
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 2, 2013

What would I need to modify in above code to get it to work with JIRA 4.4.5?

Any help appreciated ;o)

Ryan Aherne
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 2, 2013

For JIRA 4.4.5

function getCurrentStatus(){ var statusname; AJS.$.ajax({ url: "/rest/api/2.0.alpha1/issue/CAR-20", type: 'get', dataType: 'json', async: false, success: function(data) { statusname = data.fields.status.value.name; } }); return statusname; } alert("Status : " +getCurrentStatus())

Ryan Aherne
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 2, 2013

For JIRA 4.4.5

function getCurrentStatus(){
var statusname;
     AJS.$.ajax({
        url: "/rest/api/2.0.alpha1/issue/XVY-123",
        type: 'get',
        dataType: 'json',
        async: false,
        success: function(data) {
            statusname = data.fields.status.value.name;
        } 
     });
     return statusname;
}
 
alert("Status : " +getCurrentStatus())

1 vote
Josh Simnitt July 26, 2018

In JIRA 7, you have the option to use this code to get the current IssueKey. 

JIRA.Issue.getIssueKey(); 


So they can be combined to dynamically get the status of the issue you are viewing:

function getCurrentIssueStatus()
{
var statusname;
var issueKey = JIRA.Issue.getIssueKey();
AJS.$.ajax({
url: "/rest/api/2/issue/" + issueKey,
type: 'get',
dataType: 'json',
async: false,
success: function(data) {
statusname = data.fields.status.name;
}
});
return statusname;
}

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events