Skip to main content
Example scripts
arrow icon
To homepage
Confluence
Data centre icon
Data Center

Synchronize Content Between Two Pages

Features
Listeners
Created 1 year ago, Updated 1 month(s) ago
App in script
ScriptRunner For Confluence
ScriptRunner For Confluence
by Adaptavist
Compatibility
compatibility bullet
Confluence (7.15 - 8.6)
compatibility bullet
ScriptRunner For Confluence (7.10.0)
Language |
groovy
import com.atlassian.confluence.event.events.content.page.PageEvent
import com.atlassian.confluence.pages.PageManager
import com.atlassian.sal.api.component.ComponentLocator

def pageSource = '<PAGE_SOURCE_TITLE>'
def spaceDest = '<SPACE_DEST_KEY>'
def pageDest = '<PAGE_DEST_TITLE>'
def pageEvent = event as PageEvent

def pageManager = ComponentLocator.getComponent(PageManager)

//get page
def sourcePage = pageEvent.page
def destPage = pageManager.getPage(spaceDest, pageDest)

// check if destination page exist, if not return.
if ( !destPage ) {
    log.warn "Destination page with title '${pageDest}' not available on the '${spaceDest} space'"
    return
}

//get page body in source page
def sourcePageBody = sourcePage.bodyContent

// return if the page updated is not the pageSource.
if ( sourcePage.title != pageSource ) {
    return
}

pageManager.saveNewVersion( destPage ) { pageObject ->
    pageObject.setBodyContent(sourcePageBody)
}
Having an issue with this script?
Report it here