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

Can not call built-in script in End-points since upgrading from version 6.3.0-p5

Simon Neuville August 27, 2020

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

2 answers

1 accepted

1 vote
Answer accepted
Joshua Yamdogo @ Adaptavist
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 27, 2020

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 

Simon Neuville September 2, 2020

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

Simon Neuville September 7, 2020

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

Joshua Yamdogo @ Adaptavist
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 11, 2020

Hi @Simon Neuville

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

1 vote
Sebastian Butterweck January 7, 2021

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

Sebastian Butterweck January 7, 2021

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 ...

Joshua Yamdogo @ Adaptavist
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 7, 2021

Hi @Sebastian Butterweck ,

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

Like Zachary Hayes likes this
Sebastian Butterweck January 8, 2021

Hey Joshua Yamdogo @ Adaptavist 

 

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

 

Thx

Sebastian

Zachary Hayes August 12, 2021

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

Zachary Hayes August 12, 2021

I was able to figure out that it is now

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

(removed the 'confluence') 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events