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

  1. Select the Settings cog in the top right-hand corner of the screen. 
  2. Select Macros under ScriptRunner
  3. Select Create Custom Macro
  4. Enter a Name to identify the Macro, like Page Information
  5. Enter an optional Description, like Get the current page title, the page creator, the parent page, and the space
  6. Select Enabled to allow the macro to be added to pages. 
  7. Select None for Body Type. 
  8. Pick Block for Output Type
  9. 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> """
  10. 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:

On this page