Forums

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

How do we copy pages using ScriptRunner PageManager and deepCopyPage?

Lauren Lee
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 14, 2020

Confluence Vers: 7.1.0

Scriptrunner Vers: 6.4.0-p5

Hello, 

I am trying to copy pages based off of an event listener, and I keep getting the following error

 

java.lang.NullPointerException at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:877) at com.atlassian.confluence.pages.persistence.dao.bulk.DefaultBulkOptions$BaseBuilder.buildDefault(DefaultBulkOptions.java:90) at com.atlassian.confluence.pages.persistence.dao.bulk.copy.PageCopyOptions$Builder.build(PageCopyOptions.java:158) at com.atlassian.confluence.pages.persistence.dao.bulk.copy.PageCopyOptions$Builder$build.call(Unknown Source) at TEST_Archive_Document_2.run(TEST Archive Document 2.groovy:13)

with the code below. 

import com.atlassian.confluence.event.events.content.page.PageEvent
import com.atlassian.confluence.pages.PageManager
import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.confluence.pages.Page
import com.atlassian.confluence.pages.AbstractPage
import com.atlassian.confluence.pages.persistence.dao.bulk.copy.PageCopyOptions
import com.atlassian.confluence.pages.persistence.dao.bulk.copy.PageCopyOptions.Builder
import com.atlassian.confluence.pages.persistence.dao.bulk.DefaultBulkOptions
import com.atlassian.confluence.pages.persistence.dao.bulk.DefaultBulkOptions.Builder
import com.atlassian.confluence.pages.persistence.dao.bulk.DefaultBulkOptions.BaseBuilder

def pageManager = ComponentLocator.getComponent(PageManager)
def builderPage = PageCopyOptions.builder()

PageCopyOptions pageCopyOptions = builderPage.build();
Page originalPage = pageManager.getPage(10818720)
Page destinationPage = pageManager.getPage(10818723)
pageManager.deepCopyPage(pageCopyOptions, originalPage, destinationPage)

Additionally, I've tried using the canned CopyTree function, but have had no luck.  

 

 

1 answer

Suggest an answer

Log in or Sign up to answer
1 vote
Cornelius Gillner
Contributor
March 4, 2022

Just stumbled upon this older question.

cfValues is a map-like structure where you can get the value of any custom field on the object. Note that the keys are the field name, and not id.

 You will have to access the field value by its name, the name like you will find it in the administation for custom fields in Jira.

cfValues['nameOfField'] == 'Bug' || cfValues['nameOfField'] == 'Enhancement'

try this.

TAGS
AUG Leaders

Atlassian Community Events