Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
badges earned

Your Points Tracker
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

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

calling CopyTree built in script in own scripts for script runner 5.5.7

Hello. We need regularly copy our Q&A pages from agent internal Q&A knowledge base in confluence to several spaces for clients. Because of lack documentation about using canned CopyTree built-in script in own scripts we write a script based on the internet found examples.

But after passing params to doValidate we get an error. It seems that something changed since those posts. Here is the script source code:

import com.onresolve.scriptrunner.canned.confluence.admin.CopyTree
import com.onresolve.scriptrunner.canned.confluence.admin.ChangeContentAuthor
import com.onresolve.scriptrunner.canned.util.SimpleBuiltinScriptErrors
import com.atlassian.confluence.pages.AbstractPage
import com.atlassian.confluence.pages.PageManager
import com.atlassian.sal.api.component.ComponentLocator 
import com.atlassian.confluence.user.AuthenticatedUserThreadLocal
import groovy.json.JsonBuilder
import groovy.json.JsonSlurper
import groovy.json.JsonParserType
import groovy.transform.BaseScript
import org.apache.log4j.Level
@BaseScript CustomEndpointDelegate delegate
    httpMethod: "POST"
    , groups: ["confluence-users"]
	{ MultivaluedMap queryParams, String body ->
      log.debug("HttpBody= ${body}")
      JsonSlurper slurper = new JsonSlurper()
         return Response.serverError().entity([error: "No parameters specified"]).build()
      } else {
         //Read and validated the post parameters         
         def bodyObject = slurper.parseText(body)
         assert bodyObject instanceof Map
         if(!bodyObject?.pageTreeSource || !bodyObject?.targetParentPage || !bodyObject?.replaceToken || !bodyObject?.replaceValue) {
             return Response.serverError().entity([error: "All parameters are required: pageTreeSource, targetParentPage, replaceToken, replaceValue"]).build()

         String output;
         def titleTransform = ""
         output += "pageTreeSource=${bodyObject.pageTreeSource}, targetParentPage=${bodyObject.targetParentPage}, replaceToken=${bodyObject.replaceToken}, replaceValue=${bodyObject.replaceValue}\n"
         //Define the CopyTree canned script input parameters
         def inputs =[             
             (CopyTree.FIELD_SRC_PAGE_ID): "[\"${bodyObject.pageTreeSource}\"]",
             (CopyTree.FIELD_TARGET_PAGE_ID): "[\"${bodyObject.targetParentPage}\"]",             
         ] as Map<String, Object>
         output += "CopyTree input: $inputs"         
         CopyTree copyTree = new CopyTree()         
         def errorCollection = (SimpleBuiltinScriptErrors) copyTree.doValidate(inputs as Map, false)
         if(errorCollection.hasAnyErrors()) {
             log.warn("Could not copy page tree: $errorCollection")
             return Response.serverError().entity([error: errorCollection.getErrorMessages()]).build();
         return Response.ok().entity(output).build(); 


Here is the error message:

"message":"assert nodes.size() <= 1\n | | |\n | 12 false\n [[, \", 5, 1, 6, 0, 9, 6, 1, 0, \", ]]","stack-trace":"Assertion failed: \n\nassert nodes.size() <= 1\n | | |\n | 12 false\n [[, \", 5, 1, 6, 0, 9, 6, 1, 0, \", ]]\n\n\tat com.onresolve.scriptrunner.canned.confluence.admin.CopyTree.doValidate(CopyTree.groovy:245)\n\tat Script8$_run_closure1.doCall(Script8.groovy:47)\n\tat\n\tat\n","status-code":"INTERNAL_SERVER_ERROR"}

Can anyone help? 

1 answer

For anyone needing a solution to this:


You do not need to pass the brackets ( [ and ] ) as strings in the arguments. These brackets are there to put the argument value in a list. Therefore, pass your arguments like this:

inputs = [
   FIELD_SRC_PAGE_ID : ["65593"],
   FIELD_TARGET_PAGE_ID: ["someOtherValue"]

I encountered the same problem with same error message. This solution worked for me

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Marketplace Apps & Integrations

New cloud apps roundup - June 2021

Since our last roundup in April, Atlassian's Marketplace Partners have added over 100 new cloud apps to the Atlassian Marketplace to help your teams work more efficiently. Let’s take a quick look a...

467 views 5 12
Read article

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