Javascript does not work in User Macro in Confluence
Asked by nallu:

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](https://community.atlassian.com/t5/image/serverpage/image-id/67776iC4820E8EA58EBB42/image-size/large?v=v2&px=999 "Screen Shot 2019-09-30 at 6.17.23 PM.png")


Answers:
author: Stephen Deutsch
body: 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.


author: Scott Theus
body: Hi [@nallu](/t5/user/viewprofilepage/user-id/1652434) ,

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

-Scott


Tags: confluence-server

macro

server

user-macro