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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • 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

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

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

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

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

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

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

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

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

Hey @Joshua Yamdogo _ Adaptavist 

 

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

 

Thx

Sebastian

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Confluence

Announcing Team Calendars in Confluence Data Center

Hi Community! We're thrilled to share that Team Calendars for Confluence is now a built-in feature for Confluence Data Center releases 7.11 and beyond.  A long time favorite,  Team Cale...

78 views 0 3
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