Forums

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

Getting the issue type from edit screen

Sandesh TM
Contributor
January 10, 2024

We need to get the issue type from edit screen through Javascript. How can get this details? Is there any function there similar to getting the issue id or issue key like the below?

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

2 answers

0 votes
Radek Dostál
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.
January 11, 2024

I don't think there is a method for issue type specifically (I don't see one either browsing a bit through the js methods). Alternative could be workaround from https://community.atlassian.com/t5/Jira-Software-questions/How-to-get-the-Summary-of-the-Issue-Using-JQuery-or-JavaScript/qaq-p/601115 which if modified seems to work:

function getIssueType() {
var key = this.JIRA.Issue.getIssueKey();
var issueType;
AJS.$.ajax({
url: "/rest/api/2/issue/" + key,
type: 'get',
dataType: 'json',
async: false,
success: function(data) {
issueType = data.fields.issuetype.name;
}
});

return issueType;
};

getIssueType();

 

Not perfect but does the job if nothing else works.

 

You probably could just use something like `document.querySelector("path to issuetype element")` and then get the issuetype from that as well.

E.g.

document.querySelector("#type-val").innerText;
// ' Task'
document.querySelector("#type-val").innerText.trim();
// 'Task'

 

I would say using the getter is better to avoid spamming additional ajax calls to Jira, with trim this should work fine to remove the whitespace.

0 votes
Fazila Ashraf
Community Champion
January 11, 2024

Hi @Sandesh TM 

What is the hosting type and version of your Jira?

Suggest an answer

Log in or Sign up to answer