Forums

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

Javascript does not work in User Macro in Confluence

nallu September 30, 2019 edited

Hi, 

I have created a user macro in confluence. The user macro template has custom javascript. 

When I placed that javascript in side the HTML Macro, It works fine on the page. But, If I put it in the user macro and include the user macro in the page, it does not work. 

Can anyone please let me know what I am doing wrong here...

Script:

<script>

$('.jira-issue-key').ready(measure());

function measure(){
console.log("allu inside measure");
if ($('.jira-issue-key').length > 0 ) {
console.log("nallu");
$(document).ready(function(){

var array = document.getElementsByClassName("jira-issue-key");
var i = 0;
var key = "";
var hreftext = "";
while(!key.includes('FEATURE') && i < array.length ){

hreftext = document.getElementsByClassName("jira-issue-key")[i].href;
key = hreftext.split('/')[(hreftext.split('/')).length - 1];
i++;
}

if(key.includes('FEATURE')) {
$.getJSON(`https://devconfluence2.******.com/plugins/servlet/applinks/proxy?appId=*********&path=https://athenajira.*******.com/rest/api/latest/issue/${key}`, function(data) {

var pathToGA = '';
var techinicalRisk = '';
var targetGaRelease = '';
var changeManagementTier = '';
var serviceline = '';

if(data["fields"]["customfield_15723"]) { pathToGA = data["fields"]["customfield_15723"]["value"]; }

if(data["fields"]["customfield_17105"]) { techinicalRisk = data["fields"]["customfield_17105"]["value"]; }

if(data["fields"]["customfield_16006"]) { targetGaRelease = data["fields"]["customfield_16006"]["value"]; }

if(data["fields"]["customfield_15709"]) { changeManagementTier = data["fields"]["customfield_15709"]["value"]; }

if(data["fields"]["customfield_15722"]) { serviceline = data["fields"]["customfield_15722"]["value"]; }

if(pathToGA) {
document.getElementById("pathToGA").innerHTML = pathToGA;
} else {
document.getElementById("pathToGA").innerHTML = "";
}

if(techinicalRisk) {
document.getElementById("technicalrisk").innerHTML = techinicalRisk;
} else {
document.getElementById("technicalrisk").innerHTML = "";
}

if(targetGaRelease) {
document.getElementById("targetGaRelease").innerHTML = targetGaRelease;
} else {
document.getElementById("targetGaRelease").innerHTML = "";
}

if(changeManagementTier) {
document.getElementById("changeManagementTier").innerHTML = changeManagementTier;
} else {
document.getElementById("changeManagementTier").innerHTML = "";
}

if(serviceline) {
document.getElementById("serviceline").innerHTML = serviceline;
} else {
document.getElementById("serviceline").innerHTML = "";
}

});
}
});
}
}
</script>

 

User Configuration's Screenshot

Screen Shot 2019-09-30 at 6.17.23 PM.png

 

 

 

2 answers

0 votes
Stephen Deutsch
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.
September 30, 2019 edited

Hi nallu,

I believe you're having an issue with $ being interpreted as a variable in Velocity. Simply replace all your $ signs with the word jQuery (capitalized that way) and your user macro should work.

0 votes
Scott Theus
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.
September 30, 2019

Hi @nallu ,

I believe this is a bug, please see https://jira.atlassian.com/browse/CONFSERVER-26104.

 

-Scott

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, likes for trees, atlassian community, social impact, tree planting campaign, community kudos, atlassian giving, environmental impact, sustainability, likes for good, atlassian social responsibility, community challenge

Make every click count—help us plant 50,000 trees! 🌳

Want to make your everyday Community actions directly contribute to reforestation? The Atlassian Community can achieve this goal by liking a post, attending an ACE, sending your peers kudos, and so much more!

Help us plant more trees
AUG Leaders

Atlassian Community Events