Example: Return Page Information
You can create a macro to pull the page information (like page title, the page creator, the parent page, and the space) of Confluence content onto a Confluence page.
Create the macro
- Select the Settings cog in the top right-hand corner of the screen.
- Select Macros under ScriptRunner.
- Select Create Custom Macro.
- Enter a Name to identify the Macro, like Page Information.
- Enter an optional Description, like Get the current page title, the page creator, the parent page, and the space.
- Select Enabled to allow the macro to be added to pages.
- Select None for Body Type.
- Pick Block for Output Type.
Enter the following script into the Script to Execute field:
groovy//get page info def pageId = parameters.pageId def uri = "/wiki/api/v2/pages/${pageId}" def pageInfo = get("$uri") .header('Content-Type', 'application/json') .asObject(Map).body //Get creator info assert pageInfo def creatorId = pageInfo.authorId uri = "/wiki/rest/api/user?accountId=${creatorId}" def creatorInfo = get("$uri") .header('Content-Type', 'application/json') .asObject(Map).body //Get parent page info pageId = pageInfo.parentId uri = "/wiki/api/v2/pages/${pageId}" def parentInfo = get("$uri") .header('Content-Type', 'application/json') .asObject(Map).body //Get space info def spaceId = pageInfo.spaceId uri = "/wiki/api/v2/spaces/${spaceId}" def spaceInfo = get("$uri") .header('Content-Type', 'application/json') .asObject(Map).body return """ <p><strong>Current Page</strong>: <a href="/wiki${pageInfo._links.webui}">$pageInfo.title</a></p> <p><strong>Page Creator</strong>: <a href="${creatorInfo._links.base}/people/${creatorId}">$creatorInfo.publicName</a></p> <p><strong>Parent Page</strong>: <a href="/wiki${parentInfo._links.webui}">$parentInfo.title</a></p> <p><strong>Space</strong>: <a href="/wiki${spaceInfo._links.webui}">$spaceInfo.name</a></p> """
- Select Save.
Results
The macro appears on the main Macros page:
Users in your instance can now add it to Confluence pages. When it's added and the page is published, it appears like this: