Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to get issue id in javascript using web-resource module

Dheeraj Kumar Aggarwal
Contributor
April 4, 2012

I am trying the following way, but failed :

<web-resource key="view-issue-page-web-resources" name="Web Resources">

<resource type="download" name="viewIssue.js" location="includes/js/viewIssue.js">

<param name="issueId" value="${issue.id}"/>

</resource>

<context>jira.view.issue</context>

</web-resource>

AJS.params.issueId is returning undefined.

How can I get the issue id in the js file?

1 answer

0 votes
Dieter
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 4, 2012

I think you already know that you can get the project key using

pkey = AJS.$("#key-val").text()


If the key is not sufficient you can the use Ajax to get the rest about the issue (Jira 5 required)

function getIssueByKey(pkey)
{
var result = null;
     AJS.$.ajax({
        url: "/rest/api/2.0/issue/"+pkey,
        type: 'get',
        dataType: 'json',
        async: false,
        success: function(data) {
            result = data
        } 
     });
     return result;
}
id = getIssueByKey(pkey).id

But honestly right now i also don't know how to do that easier or for Jira 4, If there is time during the holiday i will look at that closer

Dheeraj Kumar Aggarwal
Contributor
April 4, 2012

Thanks Dieter

But I am already using the one below. I don't want to use the hack method and I want to do it in a standard way and I am not able to find that.

var editButton = AJS.$('#editIssue');

if(editButton){

var href = editButton.attr("href");

if(href.indexOf('?id=') > -1){

issueId = href.substring(href.indexOf('?id=')+4);

}

}

Dieter
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 4, 2012
Hi Dheeraj, just for my curiosity: why is the issue key not sufficient?
Dheeraj Kumar Aggarwal
Contributor
April 5, 2012

Hi Dieter, I am developing a plugin, which has a db table with many to many relationship with JIRA issue id directly. That is the only reason, why I want to use issueId.

One more thing, my problem is still not resolved, because it is possible, that in future versions of JIRA, they change id of html elements. That's why I was asking, is there any standard way of doing that like AJS.params.issueId ?

Anyways Thanks Dieter for the help and quick reply.

Dieter
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 5, 2012
If you need the id just on the view issue screen you might create an issue operation plugin module that instead of a link just renders a div element with id myplugin-issue-id and your issue id as element content. This divwould be placed n the view velocity template of the plugin. To make sure that this doesn't look strange hide this issue link operation using javascript again. Seems a lottle bit tricky but it makes sure you will always get your issue id from the same id

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events