Editing macro at the page through ScriptRunner for Confluence

zaharovvv_suek_ru
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.
January 14, 2020

I have a confluence page. 

Is it possible:
1. Find macro on the page which has name `Page properties`
2. Is it possible to update fields of macro `Page Properties` such as `Тип`, `Код`, `Модуль` programmatically through Confluence API?
3. Is it possible to delete field such as `Ссылка` programmatically through Confluence API?

I've attached an image to the message to clarify what I want.
Is it possible to do?

Confluence page for forum.png

1 answer

1 accepted

1 vote
Answer accepted
Sven Schatter _Lively Apps_
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
January 14, 2020

Hi @zaharovvv_suek_ru,

yes, this is possible! It just requires quite a bit of programming on your side. In fact, our Confluence app Diary actually makes use of this exact mechanism. Except, it doesn't use the Page Properties table, but a table inside it's own macro body. However, if you think it helps you, you can go have a look at how we did it. :)

Basically, you first want to get the Storage Format of your page via the Confluence REST API. You can then parse the XHTML, change the <table> in the Page Properties Macro however you want, and save the manipulated Storage Format again, using another Confluence REST API endpoint.

I've also already answered a very similar question to this over at the Developer Community - might also be worth checking out.

Best regards,
Sven

Trang Ngoc Nguyen July 5, 2024

@Sven Schatter _Lively Apps_ I am trying to do something similar in a custom macro but has some problems, could you please help me out?

  • The macro I try to make get data from Jira and put it on Confluence.
  • The logic I want is that: 
    • If there is no data from Jira, update the status element on the page, keep the rest of the content
    • If there is data from Jira, update the whole content
  • Problem I am facing
    • I can't seem to get the rendered view of the macro. When using context.getEntity().bodyAsString I only get the storage view of the page, which has only the macro and parameters, not the generated data by the macro (I need the generated data to find where the status is)
    • I tried setting the body of my macro programmatically so that it will appear in the storage view, just simple by setting body = textToDisplay inside my macro, but it doesn't work either. The body is not appearing in the storage view.

Could you please advice me what I need to do in this case? Thank you very much!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events