Can I use a 'canned' script with a 'script job' in ScriptRunner for Confluence?

Thomas Berger August 6, 2017

I'd like to use the "Bulk delete comments from one or more pages" canned script on all pages of a specific space running as a script job and deteting page comments older than 60 days.

However, this script has a few user params defined and wants the user to select a page.

Not 100% sure on how to approach this? Do I build a custom 'Script CQL function' and then use the 'CQL escalation service' script job type?

 

1 answer

1 accepted

1 vote
Answer accepted
Stephen Cheesley _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.
February 12, 2018

Hi Thomas,

I think the best approach would be to get a list of the current pages for a space using the SpaceManager and PageManagers that are built-in to the Confluence API. You can then use these to call the built-in space.

I have taken the liberty of putting an example script together:

import com.atlassian.confluence.pages.PageManager
import com.atlassian.confluence.spaces.SpaceManager
import com.atlassian.sal.api.component.ComponentLocator
import com.onresolve.scriptrunner.canned.confluence.admin.BulkDeleteComments
import groovy.json.JsonBuilder

def spaceMgr = ComponentLocator.getComponent(SpaceManager.class)
def pageMgr = ComponentLocator.getComponent(PageManager.class)

// The canned script we want to use...
def canned = new BulkDeleteComments()

// Let's grab the space
def space = spaceMgr.getSpace("ds")
def ids = pageMgr.getPages(space, true).collect{ it.idAsString }

// Build the params
def scriptParams = [
"FIELD_PAGE": new JsonBuilder(ids).toString(),
"FIELD_AGE": "60",
]

// Run the script
def response = canned.doScript(scriptParams)
response["output"] // <- Return the response - don't need to do this for a built-in job but you might want to log it.

TODO: Where I do spaceMgr.getSpace("ds") you need to swap that for your desired spaces key.

If you want to test this out you can run it from a script console first. Otherwise put it into a script job to run at your desired frequency.

If you have any questions just let me know.

I hope this helps!

Steve

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events