Get issue key of link 'is Feature of Epic' using announcement banner (javascript)

Dan27 January 5, 2021

Hello,

 

I would like to add fixversion of all links type 'is Feature of Epic'.

I wrote the script for adding the fixversion for 'issues in Epic' links.

How can I get the issue key of the 'is Feature of Epic' links using announcement banner?

I tried this code (without success):

<script type="text/javascript">
jQuery(document).ready(function($) {
setInterval(function (){
var editdl = AJS.$('.links-list')
var proj = AJS.$("#project-name-val").text();
var project = proj.trim();
if(project == 'WLA WorkBacklog' || project == 'WLA Solution Intent'){
var title = document.getElementsByTagName("DT");
for(var i=0; i<editdl.length; i++){
if(title[i].innerHTML == 'is Feature of Epic'){
var div = document.getElementsByClassName("links-list");
var nodelist = div[i].getElementsByTagName("DD").length;
for(var j=0; j<nodelist; j++){
var issueKey = div[i].getElementsByTagName("dd")[j].getElementsByClassName("issue-link link-title").value
AJS.$.getJSON(AJS.contextPath() + '/rest/api/latest/issue/' + issueKey, function(data){
var value = data.fields.fixVersions.map(function(version){return version.name});
var actions = AJS.$(row).find('td.issue_actions');
AJS.$(actions).before('<td class="nav">' + value + '</td>');
});
}

}
}
}},500);
});
</script>

 

What am I doing wrong?

Thanks ,

Daniel

1 answer

0 votes
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 19, 2021

I'm not going to ask why you are doing this or why you tagged your post with scriptrunner or adaptavist ... but let's see what we can find out is going on with this script.

The first thing that seems odd to me is this:

var actions = AJS.$(row).find('td.issue_actions');

"row" is not defined anywhere. 

And in modern versions of jira, I don't see any td element with issue_actions class as specified by find('td.issue_actions').

My guess is that you want to somehow display the fixVersion of your liked issue in some way next to the status and priority. Those are not in a table or td (at least not in my jira 8.11).

My suggestion would be to try to add it after the link-summary

Try something like this (also leveraging some jquery to remove some of the for loops)

<script type="text/javascript">
AJS.$(document).ready(function() {
setInterval(function () {
var project = AJS.$("#project-name-val").text().trim();
if (project == 'WLA WorkBacklog' || project == 'WLA Solution Intent') {
AJS.$('dl.links-list dt[title="is Feature of Epic"]').next('dd').find('.issue-link.link-title').each(function(){
var link = AJS.$(this);
var url = AJS.contextPath() + '/rest/api/latest/issue/' + link.text() + '?fields=fixVersions';
AJS.$.getJSON(url, function(data){
var versionName = data.fields.fixVersions.map(function(version){return version.name});
link.closest('p').after('<p style="text-align:right;">'+versionName+'</p>');
});
});
}
}, 500);
});
</script>

Suggest an answer

Log in or Sign up to answer