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

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

Avatar

1 badge earned

Collect

Participate in fun challenges

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

Challenges
Coins

Gift kudos to your peers

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

Recognition
Ribbon

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!

Leaderboard

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
4,559,083
Community Members
 
Community Events
184
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.
{pageactivity}
{send-email} Error Message: h4. Exception ( 391 lines)
{code}
java.lang.NullPointerException: null
at com.comalatech.confluence.workflow.macros.actions.SendEmailMacro.execute(SendEmailMacro.java:107)
at com.atlassian.renderer.v2.macro.ResourceAwareMacroDecorator.execute(ResourceAwareMacroDecorator.java:51)
at com.atlassian.renderer.v2.components.MacroRendererComponent.executeMacro(MacroRendererComponent.java:192)
at com.atlassian.renderer.v2.components.MacroRendererComponent.processMacro(MacroRendererComponent.java:156)
at com.atlassian.renderer.v2.components.MacroRendererComponent.makeMacro(MacroRendererComponent.java:59)
at com.atlassian.renderer.v2.components.WikiContentRendererHandler.handleMacro(WikiContentRendererHandler.java:18)
at com.atlassian.renderer.v2.WikiMarkupParser.makeMacro(WikiMarkupParser.java:120)
at com.atlassian.renderer.v2.WikiMarkupParser.handlePotentialMacro(WikiMarkupParser.java:100)
at com.atlassian.renderer.v2.WikiMarkupParser.parse(WikiMarkupParser.java:60)
at com.atlassian.renderer.v2.components.MacroRendererComponent.render(MacroRendererComponent.java:43)
at com.atlassian.renderer.v2.V2Renderer.render(V2Renderer.java:53)
at com.atlassian.renderer.v2.plugin.PluggableV2Renderer.render(PluggableV2Renderer.java:30)
at com.atlassian.renderer.v2.V2RendererFacade.convertWikiToXHtml(V2RendererFacade.java:57)
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.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:343)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
at com.atlassian.spring.interceptors.SpringProfilingInterceptor.invoke(SpringProfilingInterceptor.java:16)
{code}
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:

pageManager.refreshPage(childPage)

 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
updatedListChildren.remove(childPage)
previousParentPage.setChildren(updatedListChildren)

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

// update list of newParentPage children
childPage.setParentPage(newParentPage)
List<Page> children = newParentPage.children
children.add(childPage)
newParentPage.setChildren(children)

// update list of newParentPage ids
List<Long> childIds = children.collect { page -> page.id }
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))
pageManager.refreshPage(childPage)
pageManager.refreshContentEntity(childPage)

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events