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

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

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
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted Jul 10, 2018 in Confluence

We want to see the templates you've created in Confluence!

Hi Community, Jessica here from the Confluence Product Marketing team!  July’s community challenge is all about sharing pictures  — and as an extension of our first post on what ...

849 views 23 12
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you