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

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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Kesha Thillainayagam
Posted Apr 13, 2018 in Confluence

We want to hear how your non-technical teams are using Confluence!

Hi Community! Kesha (kay-sha) from the Confluence marketing team here! Can you share stories with us on how your non-technical (think Marketing, Sales, HR, legal, etc.) teams are using Confluen...

872 views 21 10
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