How to set a default value for the link type when creating an issue link
Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.
Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Summary
The information on this page relates to customisations for Jira applications. Consequently, Atlassian Support cannot guarantee the provision of any support for the steps described on this page as customisations are not covered under Atlassian Support Offerings. Please be aware that this material is provided for your information only and that you use it at your own risk.
By default, when creating an issue link, Jira sorts the options in the link type dropdown list in alphanumeric order of the link type's name; there is no option to choose a default link type.
While it is possible to work around this by editing the link type and changing the name of the desired default link type to start with "1" or "AAA", there is a second problem - once a user selects a link type, Jira will remember this link type and use it as the user's default in the future, until that user creates a link of a different type. This overrides alphanumeric order and cannot be changed.
Solution
The following JavaScript code can be added to the Jira announcement banner to override the default. (In the example below, the default is set to "relates to" - to change it, simply change the value of defaultLinkType.)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<script type="text/javascript">
function overrideDefaultLinkType(loadEvent) {
// The link type to use as the default.
defaultLinkType = "relates to";
// Check the URL correctly depending on whether this is an XHR request.
switch (loadEvent.type) {
case "load":
url = loadEvent.currentTarget.responseURL;
break;
case "DOMContentLoaded":
url = document.location.href;
break;
default:
url = null;
}
if (url !== null && url !== undefined) {
if (url.indexOf("/create") >= 0 || url.indexOf("/edit") >= 0) {
linkTypeElement = document.getElementById('issuelinks-linktype');
if (linkTypeElement !== null) {
linkTypeElement.value = defaultLinkType;
}
} else if (url.indexOf("/LinkJiraIssue") >= 0) {
waitToFixLinkType(defaultLinkType);
}
}
};
// Wait for the Link Issue dialog to populate the drop-down list before fixing it.
function waitToFixLinkType(linkType) {
window.setTimeout(function() {
linkTypeElement = document.getElementById('link-type');
if (linkTypeElement !== null) {
linkTypeElement.value = linkType;
} else {
waitToFixLinkType(linkType);
}
}, 100);
}
// Override the link type after the page's content loads.
window.addEventListener('DOMContentLoaded', overrideDefaultLinkType);
// In addition to the main page content Jira also loads content via subrequests, so we need to override XMLHttpRequest to override the link type after loading each subrequest.
var defaultXMLHttpRequest = window.XMLHttpRequest;
function modifiedXMLHttpRequest() {
var XHR = new defaultXMLHttpRequest();
XHR.addEventListener("load", overrideDefaultLinkType);
return XHR;
}
window.XMLHttpRequest = modifiedXMLHttpRequest;
</script>
Was this helpful?