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

How to get the new macro-id in a User Macro in Confluence 5.8?

glycoknob October 1, 2015

Hi, I'm writing a user macro that will be used multiple times on a page and that will store data unique to the macro instance on the page. My idea was to use the new REST-properties API to store the data and retrieve it using JavaScript - to distinguish the data I want to use the macro-id  

I can get the page id using $content.getIdAsString() but I'm unable to find a method to get the macro-id. 

There is a Class MacroDefinition in the API can I use this in the User Macro? How do I do it? I'm not sure how to do it in a User Macro. 

Or do I have to build a real Macro? 

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

2 votes
Answer accepted
Volodymyr Krupach
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 1, 2015

Hi Martin,

I do not see reliable way to get and persist ids for a User Macro. You can try some tricks with JavaScript: Store macro configs through REST-properties API under pageId key + counter. Where counter is handled/kept through JavaScript/HTML. Bodies of you templates are processed one by one when a page is rendered in a browser. So you can JavaScript that checks for some JavaScript variable (e.g. myUniguqMacroCounter) and if it's undefined you assume that it's a first instance for the current page and assign myUniguqMacroCounter = 1 and set some attribute in a HTML dom element for this macro instance. The second instance finds that myUniguqMacroCounter is already defined and add +1 and again store this in its bode and so on. Each of the instances tries to retrieve properties stored under key "pageId + myUniguqMacroCounter" and stores the config under this key.

But this does NOT look reliable and too much JavaScript tricks. I suggest you to convert to the "real macro".

glycoknob October 5, 2015

Thanks. For now setting a parameter in the Macro Creation Dialogue does the job, I'll look into the complete Macro API.

TAGS
AUG Leaders

Atlassian Community Events