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

Next challenges

Recent achievements

  • Global
  • Personal


  • Give kudos
  • Received
  • Given


  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

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 Edited

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 ' + '*****:*****'.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!!


1 answer

Hi André!

After examining the source code, I've determined that this might be an issue which has to do with this bug which was fixed some time ago:

You might want to try updating ScriptRunner to see if that fixes this problem for you. However, I'd encourage you to try using a feature such as Remote Control so that you don't have to keep credentials in your scripts.

Here's some documentation you'll find helpful if you go that route:

Hi, @Tiffany Wortham !

Well, I stopped that development for a while and, although my ScriptRunner is a little bit outdated, recently I discovered that there's a way that I could get where I wanted with a simpler solution. So I just used the Bob Swift's Jira CLI plugin and achieved my objectives with just a few commands. It worked very well.

I appreciate your help and the informations, thank you very much :)

Suggest an answer

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

What do you think is the most *delightful* Confluence feature? Comment for a prize!

- Create your own custom emoji 🔥 - "Shake for Feedback" on mobile 📱 - An endless supply of GIFs via GIPHY 🤩 Is there anything quite as nice as a pleasant surprise? Comment below with what...

415 views 23 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