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

Hi,

 

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?

 

Thanks,

-lee.

1 answer

1 accepted

1 vote
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):

 

<script>
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:
error.png
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?

Thanks!!!
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:

AJS.Meta.get('space-name')

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

alert(AJS.Meta.get('space-name'));

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...

 

Thanks,

-Lee

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:

https://developer.atlassian.com/confdev      

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

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Kesha Thillainayagam
Posted Friday in Confluence

We want to hear how your non-technical teams are using Confluence!

Hi Community! Kesha (kay-sha) from the Confluence marketing team here! Can you share stories with us on how your non-technical (think Marketing, Sales, HR, legal, etc.) teams are using Confluen...

246 views 11 9
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