We have a sequence diagram macro for Confluence with a growing user base. Recently we are working on Export to PDF support.
One of the strength of our app is it doesn’t send user data outside of Confluence. We want to maintain that. To support PDF rendering, we are thinking of generating image attachment when user saves macro content. The attachment needs to be named with macro id, so that exporting to PDF can use it for static content.
After exploring the documentation we can’t find how to get macro id in a dynamic content macro. Can someone advise on this?
@dmorrow would you be able to help here? I’m new to Confluence Cloud development, and I’m getting blocked by this issue as well.
I’m not able to get macro.id neither through Javascript API, or any other means. For example I was trying to use context parameters in editor url, but with no luck.
Regarding the issue about macro ID not being available to the editor, I thought about creating an issue to make it available, but I decided to create an issue for the semantics of the macro ID to be documented - see CONFCLOUD-70816. The reason I went this way is because it seems the macro ID can mutate so I’m not even sure how useful it is.
In the absence of clear macro ID semantics and availability in enough contexts to be useful, perhaps you can allocate your own immutable ID an embed it in your macro data.
Overall, the gaps in the APIs makes it difficult to pass data between the view and edit modes. Here’s a summary of the issues I am aware of (not all state related, but they add to the confusion):
CONFCLOUD-62377: AP.confluence.getMacroData() is not available in view mode
CONFCLOUD-69962: Connect JS AP.getMacroBody does not work in Preview Mode
To pass data between the view and edit modes, you may be able to use the following hacky technique:
When the dynamic content macro view resource opens in preview mode (pass the {output.type} context parameter), call AP.context.getContext(callback) and within the callback extract the content ID by referencing context.confluence.content.id and set a content property with the value using AP.confluence.setContentProperty().
Later, when in the macro’s custom editor, you won’t be able to use AP.context.getContext(callback) to determine the current content ID due to CONFCLOUD-70815, but you will be able to call AP.confluence.getContentProperty() to retrieve the content ID. Once you have the content ID, you can make further calls to set and retrieve properties to/from the content.
No problems @Grzegorz.Tanczyk. I was a bit surprised by this also and have doubts in the back of my mind about my observations and interpretation of macro.id behaviour so it will be interesting to see what comes out of CONFCLOUD-70816.
Thanks for putting all this together.
I would like to contribute a use case that our own immutable ID won’t work. We wanted to detect whether a macro is a clone on the same page.
When you copy a macro, the macro data is copied over It is not a semantically correct macro id anymore, because two macros now share the same immutable id.
Workaround: we have two options to detect duplication,
Read the page as “atlas_doc_format” and check whether there are more than one instances with our own immutable ID. However, the content API has a latency of a few seconds. (correct?) So you may not see the newly pasted macro.
Read the page as “atlas_doc_format”, if there is an instance that has the same immutable ID but has a different macro ID, then there is a duplication. Most like the “current” macro is a copy of another macro and we should update our immutable ID.
Is there still no way to identify a macro that has been copy pasted on the same page? Our customers for the Properties app are affected by this lack of functionality and have to use workarounds instead of just copy & pasting a macro. It would be great if Atlassian could just assign a permanent, fixed unique ID for every macro.