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

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to get a Confluence Page Property with Script Runner Edited

 Hello

For some automation tasks, I would like my groovy Script Runner code to get a page "Property" from "Page properties" macro https://confluence.atlassian.com/doc/page-properties-macro-184550024.html

Instead of parsing page content for macro, I would like to use relevant service API:

import com.atlassian.confluence.pages.Page
import com.atlassian.confluence.pages.PageManager
import com.atlassian.confluence.plugins.pageproperties.api.service.PagePropertiesService
import com.atlassian.sal.api.component.ComponentLocator
import com.onresolve.scriptrunner.runner.customisers.WithPlugin

@WithPlugin("confluence.extra.masterdetail")

def pagePropertiesService = ComponentLocator.getComponent(PagePropertiesService) as PagePropertiesService
def pageManager = ComponentLocator.getComponent(PageManager) as PageManager
Page page = pageManager.getPage(pageId)
pagePropertiesService.getReportFromContent(page)

which then should allow me to use PagePropertiesMacroInstance.getPagePropertyReportRow()

But at the moment pagePropertiesService is null after ComponentLocator.getComponent

May you please point me what is wrong in that code?

Or is there an easier way to access Page Property?

Thank you in advance for your help

 

 

 

1 answer

Finally found the proper way to get a plugin OSGi service reference:

import com.atlassian.confluence.pages.Page
import com.atlassian.confluence.pages.PageManager
import com.atlassian.confluence.plugins.pageproperties.api.service.PagePropertiesService
import com.atlassian.sal.api.component.ComponentLocator
import com.onresolve.scriptrunner.runner.ScriptRunnerImpl
import com.onresolve.scriptrunner.runner.customisers.WithPlugin

@WithPlugin("confluence.extra.masterdetail")

def pagePropertiesService = ScriptRunnerImpl.getOsgiService(PagePropertiesService) as PagePropertiesService
def pageManager = ComponentLocator.getComponent(PageManager) as PageManager
Page page = pageManager.getPage(pageId)

pagePropertiesService.getReportFromContent(page)
.getMacroInstancesForId("metadata").find { it.getPagePropertyReportRow().containsKey("Document ID") }
.getPagePropertyReportRow().get("Document ID").getDetailStorageFormat()

Hope this helps

 

 

 

 

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Marketplace Apps & Integrations

5 mobile apps for Jira Cloud to boost productivity

  It’s very important to have access to the workflow process from anywhere. Especially if you manage the work of others. There is no difference whether you’re out of office, or drive a ca...

260 views 2 5
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you