Can not call built-in script in End-points since upgrading from version 6.3.0-p5
Asked by Simon Neuville:

Hello Atlassian Community!

I've got a question related to **ScriptRunner** and its **canned scripts in Confluence**.

I have implemented a custom REST-Endpoint recently. This REST-Endpoint calls one of the Built-In scripts provided by scriptrunner. It does so by importing

```
import com.onresolve.scriptrunner.canned.confluence.admin.CopyTree
```

and executing the following block:

```
def copyTree = new CopyTree()
def errorCollection = copyTree.doValidate(copyTreeInputParameters, false)
```

with parameters:

```

[ (CopyTree.FIELD_SRC_PAGE_ID) : [sourcePageId.toString()],
(CopyTree.FIELD_TARGET_PAGE_ID) : [space.getHomePage().getId().toString()]
]
```

Since the upgrade to ScriptRunner version 6.6.0 from 6.3.0-p5, this is not possible anymore, because the constructor is not found. Calling these scripts from a REST-Endpoint is not officially supported by ScriptRunner, and therefore this is understandable that the API can change.

(Here is the error)

```
groovy.lang.GroovyRuntimeException: Could not find matching constructor for: com.onresolve.scriptrunner.canned.confluence.admin.CopyTree()
```

Nonetheless, **I'd like to be able to copy this pagetree from one project to another in the REST-Endpoint**.

Any help on either of the points below would be greatly appreciated:

* An alternative way on calling this canned script
* An alternative way on copying a pagetree inside the REST-Endpoint

Thank you for your time!

Simon Neuville


Answers:
author: Joshua Yamdogo @ Adaptavist
body: Hi Simon,

You are correct - there were significant changes to CopyTree within the last couple of releases. You might try changing your endpoint code and running CopyTree like this:

```
import com.onresolve.scriptrunner.canned.confluence.admin.copytree.CopyTree
import com.onresolve.scriptrunner.canned.confluence.admin.model.copytree.CopyTreeCommand
import 
com.onresolve.scriptrunner.canned.confluence.admin.model.copytree.CopyTreeCommandWithCodeField
import com.onresolve.scriptrunner.runner.ScriptRunnerImpl

def copyTree = ScriptRunnerImpl.scriptRunner.createBean(CopyTree)
def command = new CopyTreeCommandWithCodeField(
    sourcePageIds: [sourcePageId],
    targetParentIds: [space.getHomePage().getId()]
)

def errorCollection = copyTree.validate(command, false)
```

I can't confirm it will work as I've not thoroughly tested it, but it should resolve that constructor error you're receiving.

Let me know if you get it to work! :)

Regards,

Josh

comments: author: Simon Neuville
body: Hi Josh,

thank you for taking the time to answer this question! I will try this out in the coming days and report back here.

Kind regards,

Simon


author: Simon Neuville
body: Hi Josh,

great stuff: this worked like a charm. Once again, thank you for the quick and correct answer.

Just out of curiosity, how would one find out about these inner-functionings when a ScriptRunner version is updated? Are you just involved in the development process, or is there another source if information?

Thank you and kind regards,

Simon


author: Joshua Yamdogo @ Adaptavist
body: Hi [@Simon Neuville](/t5/user/viewprofilepage/user-id/3993825)

I'm an engineer on the ScriptRunner for Confluence team, so I was aware of the particular changes here. As far as I know, there really isn't a source of information that you could track to manage these changes. Like you said before, your use case isn't officially supported.

That being said, this script really only changed because of some major refactoring we're doing within the codebase. I can't promise the API will never change again (it probably will), but I wouldn't think another round of significant changes are likely. Even so, we're generally happy to answer your API questions on Community. :)

Regards,

Josh


author: Sebastian Butterweck
body: Hey [Joshua Yamdogo @ Adaptavist](/t5/user/viewprofilepage/user-id/1124621)   

I'm trying to transfer your solution to the copy space script, which in my case stopped working because of the same error.  

That's what I got so far, but it's just wild guessing, especially on the command parameters.

```
import com.onresolve.scriptrunner.canned.confluence.admin.CopySpace
import com.onresolve.scriptrunner.canned.confluence.admin.model.CopySpaceCommand
import com.onresolve.scriptrunner.runner.ScriptRunnerImpl

def copySpace = ScriptRunnerImpl.scriptRunner.createBean(CopySpace)
def command = new CopySpaceCommand(
sourceSpaceKey: sourceSpace,
key: targetKey,
name: targetName
)

def errorCollection = copySpace.validate(command, false)
```

<br />

Would you be so kind and point me in the right direction?

This is the error i'm currently getting:

```
groovy.lang.MissingPropertyException: No such property: key for class: com.onresolve.scriptrunner.canned.confluence.admin.model.CopySpaceCommand
```

Ist there any documentation on this that I did not find on the web?  

BR,

Sebastian

comments: author: Sebastian Butterweck
body: Oh, never mind, looks like these are the parameters:

```
def command = new CopySpaceCommand(
   sourceSpaceKey: sourceSpace,
   targetSpaceKey: targetKey,
   targetSpaceName: targetName
)
```

What do I need to call after the validate to actually execute the command? At the moment, its not copying anything yet ...


author: Joshua Yamdogo @ Adaptavist
body: Hi [@Sebastian Butterweck](/t5/user/viewprofilepage/user-id/2636320) ,

Validating and then executing seems to work for me:

```
import com.onresolve.scriptrunner.canned.confluence.admin.CopySpace
import com.onresolve.scriptrunner.canned.confluence.admin.model.CopySpaceCommand
import com.onresolve.scriptrunner.runner.ScriptRunnerImpl

def sourceSpace = 'ds'
def targetKey = 'ff'
def targetName = 'ff'

def copySpace = ScriptRunnerImpl.scriptRunner.createBean(CopySpace)
def command = new CopySpaceCommand(
    sourceSpaceKey: sourceSpace,
    targetSpaceKey: targetKey,
    targetSpaceName: targetName
)

def errorCollection = copySpace.validate(command, false)
if (!errorCollection) {
    copySpace.execute(command)
}
```

```
> [output: Space copied to ff]
```

Regards,

Josh


author: Sebastian Butterweck
body: Hey [Joshua Yamdogo @ Adaptavist](/t5/user/viewprofilepage/user-id/1124621)

that helped a lot. Thx. Didnt know the syntax how to execute the command.

Thx

Sebastian


author: Zachary Hayes
body: [Joshua Yamdogo @ Adaptavist](/t5/user/viewprofilepage/user-id/1124621) we just updated from 6.19.0 to 6.32.0 and scriptrunner is now unable to resolve com.onresolve.scriptrunner.canned.confluence.admin.model.CopySpaceCommand  

Is there a new solution? Thanks


author: Zachary Hayes
body: I was able to figure out that it is now  

com.onresolve.scriptrunner.canned.admin.model.CopySpaceCommand  

(removed the 'confluence')


Tags: confluence-server

rest

scriptrunner

server