Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.
×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:
Thank you for your time!
Simon Neuville
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey Joshua Yamdogo @ Adaptavist
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)
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 ...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey Joshua Yamdogo @ Adaptavist
that helped a lot. Thx. Didnt know the syntax how to execute the command.
Thx
Sebastian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Joshua Yamdogo @ Adaptavist 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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I was able to figure out that it is now
com.onresolve.scriptrunner.canned.admin.model.CopySpaceCommand
(removed the 'confluence')
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.