Forums

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

Scriptrunner Script Can't import PageManager and ComponentLocator - how to convert?

Andrei Antonescu June 14, 2023

We needed a script to modify specific content across our pages so we don't need to do it manually. I got the free trial of Scriptrunner to do this, and saw a sample script provided to achieve it, but it must be older because I guess some of the components are now deprecated on the current version of Confluence, specifically the first two lines give the "unable to resolve class com.atlassian.confluence.pages.PageManager" and "unable to resolve class com.atlassian.confluence.pages.ComponentLocator".

 

import com.atlassian.confluence.pages.PageManager
import com.atlassian.sal.api.component.ComponentLocator
import org.jsoup.Jsoup

def pageManager = ComponentLocator.getComponent(PageManager)
def rootPage = pageManager.getPage('TEST PAGE') //You can change this line to point to the right parent page.
rootPage.children.each { page ->
log.debug "Inspecting page ${page.title}"
def body = page.bodyContent.body
def parsedBody = Jsoup.parse(body)
def PlaceholderVar = parsedBody.select('contains(www.exampleforediting.com)')
if (!PlaceholderVar.empty) {
log.debug "Found table header with placeholder text: ${PlaceholderVar}"
pageManager.saveNewVersion(page) { pageObject ->
PlaceholderVar.html("www.sampleforediting.com")
pageObject.setBodyAsString(parsedBody.toString())
}
}
}

 

The thing is, I'm not a coder or developer. I just wanted a quick way to update some content across our pages using an existing script template and just tweaking a few things to fit our needs, to avoid tedious work later. So I have no idea on how to change this to work, and what changing to newer methods would entail as far as changing the rest of the script. Any help would be appreciated.

0 answers

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events