Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Javascript does not work in User Macro in Confluence 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
Scott Theus Community Leader Sep 30, 2019

Hi @nallu ,

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

 

-Scott

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.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Posted in Confluence

What do you think is the most *delightful* Confluence feature? Comment for a prize!

- Create your own custom emoji 🔥 - "Shake for Feedback" on mobile 📱 - An endless supply of GIFs via GIPHY 🤩 Is there anything quite as nice as a pleasant surprise? Comment below with what...

494 views 24 9
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you