Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Read current issue id with javascript

Uwe Sauerbrei December 19, 2012

Is there a way to use JavaScript (in the comment area of a custom field) to read the current issue id?

Regards Uwe

5 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

6 votes
Answer accepted
JamieA
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.
December 19, 2012
AJS.$("meta[name='ajs-issue-key']").attr("content")

in recent versions of jira. Think there is also a helper js function that will give you it.

Uwe Sauerbrei December 19, 2012

I will try it, thanks!

hoblerone June 14, 2015

At least from the issue navigator (when editing one of the shown issues), this doesn't work. (always returns undefined)

Kai Friemann March 9, 2016

is not working in JIRA 7.0.10
Use instead:

JIRA.Issue.getIssueId()
JIRA.Issue.getIssueKey()

 

Like anhnnp likes this
9 votes
Florin Manaila
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 22, 2013

I usually use:

JIRA.Issue.getIssueId()
JIRA.Issue.getIssueKey()

AdamG March 6, 2014

This seems to be the most reliable option now. If you are on a workflow transition screen, then JIRA.Issue will work when using transition from issue view, search results view, and JIRA Agile view. The metadata options do not work from the JIRA Agile view at least in 6.1.7.

Tomasz Stec
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.
March 18, 2015

Is there any documentation javascript JIRA object ? Could you point me some links?

AdamG March 19, 2015

I couldn't find such documentation. I don't think this is official API, it is probably just for Atlassian. Since it is javascript though we can use it. I use the development tools in Chrome, though other browsers have these too. Any that provide auto-complete will let you see the different objects and methods available.

hoblerone June 14, 2015

This one kind of "works". When editing an issue, it correctly returns the issue id, but when clicking "create" in the issue navigator. it STILL returns the id of the selected issue (instead of null because you're creating a NEW issue which has no id yet).

5 votes
frother
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 22, 2013

We have a bit of API niceness to get at meta data. It is preferred to use:

AJS.Meta.get("issue-key")

Uwe Sauerbrei April 22, 2013

Looks more impressive, thanks...

hoblerone June 14, 2015

At least from the issue navigator (when editing one of the shown issues), this doesn't work. (always returns undefined)

2 votes
Nikita_Ishkov August 27, 2019

JIRA.Issue.getIssueId()
JIRA.Issue.getIssueKey()

DOESN'T work for NEXT GEN templates based projects

I wrote bug report about it ~ 4-5 months but nothing changed

Any hacks/ideas how to resolve issueId using JS?

1 vote
hoblerone June 15, 2015

One thing that seems to work correctly for both creation and edit mode is to look in the "jiraform" form and search for the hidden "id" input. In creation dialogs, this element is not present. (JIRA 6.4)

The following will return the id as a string, or undefined for creation mode: AJS.$('form[name=jiraform] input[name=id]').prop('value').

Of course, future versions with changed HTML might easily break this, so a much preferred solution would be to fix the behavior of JIRA.Issue.getIssueId(), as that one's actually readable.

Kai Friemann March 9, 2016
In JIRA 7.0.10 the behavior is fixed:
JIRA.Issue.getIssueId()
JIRA.Issue.getIssueKey()

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events