Getting a page/space from a groovy macro

Normann P_ Nielsen _Netic_
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 19, 2022

I am running a scriprunner groovy macro on a confluence page, and I want the Space Key of the Space the page is in.

 

I simply cant figure out how to get it.

 

I have tried using com.atlassian.confluence.content.render.xhtml.ConversionContext, but I cant get this instanciated, eg the first handle to something that can lead me to the page, and hence the space...

 

2 answers

0 votes

Hi @Normann P_ Nielsen _Netic_ ,

Thanks for reaching out to Adaptavist support, this is certainly something we can help with! I've replied to the ticket you created in our queue, but I'll share my response here for anyone who encounters the same problem!

During Custom Macro creation and configuration, if you click on the blue '?' icon of the 'Macro code' box, it'll show available binding variables to this script:

Screenshot 2022-01-24 at 10.16.00.png

For your specific use case, you can use the context (ConversionContext) variable to get the Page or Space object. 

Here's an example:

import com.atlassian.confluence.pages.Page

// Entity can be either Page or Blogpost object def entity = context.getEntity()
// Check if entity is a Page object
if (entity instanceof Page) {

// Page Id def pageId = entity.getId()
// Page Title def title = entity.getTitle() // Get Space Object
def space = entity.getSpace() }

Adaptavist does have an example that uses the entity object:

https://docs.adaptavist.com/sr4c/latest/features/macros/custom-macros/reuse-existing-macros/include-all-child-pages

Please do not hesitate to reach out to us if you have further questions, I hope I have answered your query!

Kind regards,
Olly

0 votes
Fabian Lim
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 21, 2022

Hi @Normann P_ Nielsen _Netic_

You may want to contact adaptivist for a faster response if you are paying for the app: https://marketplace.atlassian.com/apps/1215215/scriptrunner-for-confluence?tab=support&hosting=cloud

Cheers

Normann P_ Nielsen _Netic_
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 22, 2022

Alreaydy on it, since no answer here :-)

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
7.15
TAGS
AUG Leaders

Atlassian Community Events