Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Spacelist 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.
August 26, 2025

As 

#set ( $allSpaces = $spaceManager.getAllSpaces() )

is deprecated, how do I use:

#set($spaces = $spaceService.find().fetchMany(new SimplePageRequest(0, 1000))

correctly - above does npot work.

 

I also assume I need spaceService in :

 

JVM_SUPPORT_RECOMMENDED_ARGS=-Dconfluence.startup.remigration.disable=true -Dupm.plugin.upload.enabled=true -Dmacro.required.velocity.context.keys=pageManager,spaceService,spaceManagerInternal,attachmentManager,permissionHelper,userAccessor,i18n,dateFormatter,res,settingsManager,htmlUtil,generalUtil,bootstrap,containerContext,action,req,content

 

Still does not work though

 

2 answers

0 votes
Adriian Semotiuk _Wombats Corp_
Contributor
August 27, 2025

Hi @Normann P_ Nielsen _Netic_ ,
I`ve tried some approaches to inject SpaceService into User Macro, but none of them were working , even after adding all of them to method allowlist and velocity context .

Here is some code that i tried : 


<b>Approach 1</b><br>
#set($componentManager = $action.getComponentManager())
#set($spaceService = $componentManager.getComponent("spaceService"))
1:$spaceService<br>

<b>Approach 2</b><br>
#set($spaceService = $containerManager.getComponent("spaceService"))
2:$spaceService<br>

<b>Approach 3</b><br>
#set($spaceService = $componentLocator.getComponent("spaceService"))
3:$spaceService<br>

<b>Approach 4</b><br>
#set($serviceAccessor = $containerManager.getComponent("serviceAccessor"))
#set($spaceService = $serviceAccessor.getSpaceService())
4:$spaceService<br>

<b>Approach 5</b><br>
#set($spaceServiceClass = $action.class.loader.loadClass('com.atlassian.confluence.api.service.content.SpaceService'))
#set($spaceService = $componentLocator.getComponent($spaceServiceClass))
5:$spaceService<br>

<b> Approach 6</b><br>
#set($spaceService = $componentLocator.getComponent("spaceService"))
6: $spaceService<br>

<b> Space Manager<b><br>
#set($spaceManager = $action.spaceManager)
8:$spaceManager<br>

Render:
image.png

And only SpaceManager that is deprecated but still usable works. So my take is probably use SpaceManager whilst it is still available)

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.
August 27, 2025

Thanks, that is apprciated - but also very disappointing.

 

Seem I have to move to Scriprunner for the job .. :-/

0 votes
Aron Gombas
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.
August 26, 2025

It may not be the actual solution, but I noticed that a closing bracket is missing from  your expression?!

This:

#set($spaces = $spaceService.find().fetchMany(new SimplePageRequest(0, 1000))

... should be:

#set($spaces = $spaceService.find().fetchMany(new SimplePageRequest(0, 1000)))

 

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.
August 26, 2025

Thanks, - that did not solve the Issue though :-) But its highly appeciated.

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.
August 26, 2025

#set ($groups = $userAccessor.getGroupNamesForUserName($action.remoteUser.name))

 

Also some deprecated stuff I need to fix 

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.
August 26, 2025

ChatGPT:

 

## Create a query for all global spaces
#set($query = $spaceService.newQueryBuilder().forAnySpace().build())

## Run the query
#set($spaces = $spaceService.find($query, $contentPermissionManager.getAllPermissionCheck()))

<ul>
#foreach($space in $spaces)
<li>
<a href="$req.contextPath/display/$space.key">$space.name</a>
($space.key)
</li>
#end
</ul>

 

Does not work though..

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events