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

How do we move correctly pages using ScriptRunner PageManager and movePageAsChild?

When I move a page I get an error in the log file:

2021-09-22 18:42:29,536 ERROR [http-nio-8090-exec-5] [comalatech.confluence.workflow.DefaultWorkflowActionManager] executeAction Error Processing Workflow Trigger action page: page: new page v.1 (4816912) trigger action: {send-email:user=@Editor in Chief@|subject=Page ready for final approval}
The page @page@ has been approved by [~@user@] and is waiting for your final approval.
{send-email} Error Message: h4. Exception ( 391 lines)
java.lang.NullPointerException: null
at com.comalatech.confluence.workflow.macros.actions.SendEmailMacro.execute(
at com.atlassian.renderer.v2.macro.ResourceAwareMacroDecorator.execute(
at com.atlassian.renderer.v2.components.MacroRendererComponent.executeMacro(
at com.atlassian.renderer.v2.components.MacroRendererComponent.processMacro(
at com.atlassian.renderer.v2.components.MacroRendererComponent.makeMacro(
at com.atlassian.renderer.v2.components.WikiContentRendererHandler.handleMacro(
at com.atlassian.renderer.v2.WikiMarkupParser.makeMacro(
at com.atlassian.renderer.v2.WikiMarkupParser.handlePotentialMacro(
at com.atlassian.renderer.v2.WikiMarkupParser.parse(
at com.atlassian.renderer.v2.components.MacroRendererComponent.render(
at com.atlassian.renderer.v2.V2Renderer.render(
at com.atlassian.renderer.v2.plugin.PluggableV2Renderer.render(
at com.atlassian.renderer.v2.V2RendererFacade.convertWikiToXHtml(
at jdk.internal.reflect.GeneratedMethodAccessor1787.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(
at com.atlassian.spring.interceptors.SpringProfilingInterceptor.invoke(
PageManager pageManager = getComponent(PageManager)
pageManager.movePageAsChild(childPage, newParentPage)

When I do the same using UI interface of confluence I don't get any errors.
I tried to add one more line after parent was changed:


 but without any luck.

1 answer

1 accepted

1 vote
Answer accepted

Maybe someone finds it useful. 

import com.atlassian.confluence.core.DefaultSaveContext
import com.atlassian.confluence.pages.Page
import com.atlassian.confluence.pages.PageManager

import static com.atlassian.sal.api.component.ComponentLocator.getComponent

PageManager pageManager = getComponent(PageManager)

Page childPage = pageManager.getPage(5275745L)
Page newParentPage = pageManager.getPage(4816980L)
Page previousParentPage = childPage.parent

// update list of previousParentPage children
List<Page> updatedListChildren = previousParentPage.children

// update list of previousParentPage ids
List<Long> updatedListIds = updatedListChildren.collect { page -> }
pageManager.setChildPageOrder(previousParentPage, updatedListIds)

// update list of newParentPage children
List<Page> children = newParentPage.children

// update list of newParentPage ids
List<Long> childIds = children.collect { page -> }
pageManager.setChildPageOrder(newParentPage, childIds)

// save content and refresh page
pageManager.saveContentEntity(childPage, new DefaultSaveContext(true, true, true))
pageManager.saveContentEntity(newParentPage, new DefaultSaveContext(true, true, true))
pageManager.saveContentEntity(previousParentPage, new DefaultSaveContext(true, true, true))

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Confluence

An update on Confluence Cloud customer feedback – June 2022

Hi everyone, We’re always looking at how to improve Confluence and customer feedback plays an important role in making sure we're investing in the areas that will bring the most value to the most c...

338 views 2 8
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