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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root


1 badge earned


Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!


Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.


Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!


Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

Getting macros from page properties via Java/Groovy API

I'm trying to write a bit of code that pulls the @ user mention details from a specific line in the page properties of a particular page.

I'm using the PagePropertiesService with getReportFromContent(page) and then getAllMacroInstances().

I can then iterate through list returned by getAllMacroInstances().   I can locate the page property am looking for BUT getDetailStorageFormat() returns a blank string.

If I use a page property that is just a string typed into the page rather than a macro I get the expected text.   It appears that getDetailStorageFormat() does not work when there is a macro involved.

It also appears that the PagePropertiesService is an undocumented API.

I borrowed quite a bit of code from here:

Has anyone else tried this?

1 answer

0 votes
Ken McClean
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.
May 02, 2023

I'm not 100% sure what you were going for with your approach to the macros, but you can search the body of a given page for an @ mention with this script

@-mentions take the form of  ri:userkey="8aab818c73caedf00173caf477050000", where the string of characters is the user ID.    Therefor if we parse the body of a page for that string, we'll turn up any @-mentions in the system.

Worth noting is the fact that while you can return the body of a page without the wiki markup, it doesn't include the @.  So you'd just be searching for the name of the user, which is ultimately less specific.


import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.confluence.spaces.SpaceManager
import com.atlassian.confluence.pages.PageManager
import com.atlassian.confluence.pages.Page
def pageManager = ComponentLocator.getComponent(PageManager)
def spaceManager = ComponentLocator.getComponent(SpaceManager)
def spaces = spaceManager.getAllSpaces()
def targetMention = 'ri:userkey="8aab818c73caedf00173caf477050000"'
spaces.each{spaceObj ->
//Iterate through all spaces in the system
 def pages = pageManager.getPages(spaceObj, false)
  pages.each{page ->
 //iterate through all pages in each space
if(page.getBodyAsString().contains("${userkey}") && page.version == page.latestVersion.version){
//Check if the page body contains the target, and ensure that the page we're checking is the latest version of the page

log.warn("${page.title} contains an @ mention of the user")}

Suggest an answer

Log in or Sign up to answer
AUG Leaders

Atlassian Community Events