How to get status value via javascript

Below js does not work for me in v5.1

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

Any help!!!!!

2 answers

1 accepted

This widget could not be displayed.
Mizan Community Champion Apr 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>

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

Any help appreciated ;o)

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())

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())

This widget could not be displayed.

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
Community showcase
Published Friday in Jira

New 5k User Limit and Other Cloud Updates

Hi all! Lauren here from the Enterprise Cloud marketing team.  I have some exciting Cloud updates from #AtlassianSummit that I wanted to share. We want everyone in your organization to be ab...

85 views 0 2
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you