It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Error on calling CopyTree built-in script via scripted post-function

Hi all.

I'm making a scripted post-function that automatizes the Confluence space creation in a certain transition of my workflow. Since I'm doing this from Jira, I needed to write a script, and it is working fine, but when I call the built-in script "Copy Tree", from Scriptrunner, I get the following error:

Cannot invoke method getSpace() on null object, stack-trace=java.lang.NullPointerException: Cannot invoke method getSpace() on null object at com.onresolve.scriptrunner.canned.confluence.admin.CopyTree.doValidate(CopyTree.groovy:237)

The block of code where I call this:

import com.atlassian.sal.api.component.ComponentLocator
import groovy.json.JsonSlurper
import groovy.json.JsonBuilder
import org.apache.http.HttpRequest
import org.apache.http.HttpRequestInterceptor
import org.apache.http.protocol.HttpContext
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.Field
import java.lang.Long

def customFieldManager = ComponentAccessor.getComponent(CustomFieldManager)
def fieldSpaceKey = customFieldManager.getCustomFieldObject("customfield_15629")

def getApplicationConnection(String url) {
def http = new HTTPBuilder(url)
http.client.addRequestInterceptor(new HttpRequestInterceptor() {
void process(HttpRequest httpRequest, HttpContext httpContext) {
httpRequest.addHeader('Authorization', 'Basic ' + 'srbr-se:se@srbr'.bytes.encodeBase64().toString())
httpRequest.addHeader('X-Atlassian-Token', 'no-check')

return http

def copyAgileSpaceTemplate(sourcePage, targetPage, projectKey) {
def copyPageTreeParams = [
FIELD_SRC_PAGE_ID: "[\"" + sourcePage + "\"]",
FIELD_TARGET_PAGE_ID: "[\"" + targetPage + "\"]",
FIELD_TITLE_TRANSFORM: "import com.atlassian.confluence.pages.AbstractPage\r\n\r\ntitleTransform = {AbstractPage p -> p.title = '${projectKey} ' + p.title}"

def confluence = getApplicationConnection("confluence_base_url")

confluence.request(Method.POST, ContentType.JSON) { req ->
uri.path = "rest/scriptrunner/latest/canned/com.onresolve.scriptrunner.canned.confluence.admin.CopyTree"
send ContentType.URLENC, [scriptParams: new JsonBuilder(copyPageTreeParams)]
response.success = { resp, json ->
log.warn("CopyTree response status: ${resp.statusLine}")
assert resp.statusLine.statusCode == 200
response.failure = {resp, json ->

copyAgileSpaceTemplate(83460136, 93683725, "ISJC")


It looks like that some part of the source code of the built-in script can't understand the parameters given.

I'm using Jira Server 7.2.3 and Scriptrunner 4.3.13.

Thanks in advance!!


0 answers

Suggest an answer

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

What project did you transition or start on Confluence with the shift to remote work?

It’s been great to hear from fellow users over the last few weeks about the best tips and fun moments you’ve had working on Confluence since the transition to working remote. I’d love to keep the c...

159 views 3 8
Join discussion

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