Forums

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

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

le tu August 21, 2017

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
Answer accepted
Thomas Schlegel
Community Champion
August 21, 2017

Hi Lee,

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

le tu August 21, 2017

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
August 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'));

le tu August 21, 2017

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

le tu August 22, 2017

10x:)

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events