how can I retrieve the name of the space i'm in (for a macro)



I'm writing a macro and I need it to save the name of the space that the macro was inserted in, can anyone help with this? is there a system variable for the space name?




1 answer

1 accepted

1 vote
Accepted answer
Thomas Schlegel Community Champion Aug 21, 2017

Hi Lee,

you get the name of the current space with: $space.getName()

could you please elaborate? when I've added this to my macro it didn't work, here's the relevant part of my code (it's inside of an HTML macro):


var title;
var url;
var space_name;

var func = function() { console.log('func loaded'); AJS.toInit(function() { console.log('toInit loaded'); AJS.$(document).ready(function() { console.log('ready loaded'); title=AJS.params.pageTitle console.log(title);
space_name=$space.getName(); console.log(space_name);

in the above 2 lines I'm getting the following error:
What am I missing? Should I include somekind of library?..can you please guide me further on how to use the $space in my macro..?
And could you guide me on where to check these kinds of stuff for further times?

Thomas Schlegel Community Champion Aug 21, 2017

Ah, you didn't mention that you want to get the space name in javascript. There you get it like this:


To make sure, you get the right name, try an alert first:


Hey Thomas Thanks a lot!!


How did you know where to find this solution? 

I've looked on google and couldn't reach any useful information...can you please explain how should I find solutions to this kind of questions in the future?...I couldn't find any good documentation for libraries that work with Atlassian or stuff like that...




Thomas Schlegel Community Champion Aug 22, 2017

You're welcome, Lee!

How to find a solution? There's no simple answer for this question. I am working as an administrator for 12 years now with Atlassian's products and try to learn from various sources, so experience is an important thing. A great source is this community. You can learn by reading answers to questions you do not even have at the moment just for learning. Here you find answers to a lot of questions, although they are sometimes not so easy to find. Communicating with other users, developers and admins in this community is always a good idea. Don't hesitate, ask your questions. With most questions, there's someone who can help you. And the next time, you already know the answer. And answer other's people questions... I am doing that for years now :-)  

Another great source is Atlassian's developer site:      

There you find tutorials for developing plugins and a lot of other useful things.

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Feb 06, 2019 in Confluence

Try out the new editing experience

Hi team, I’m Avinoam, a product manager on Confluence Cloud, and today I’m really excited to let the Community know that all customers can now try out the new editing experience and see some of the ...

1,474 views 114 8
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you