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

This widget could not be displayed.

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
Community showcase
Posted Sep 17, 2018 in Confluence

Why start from scratch? Introducing four new templates for Confluence Cloud

Hi my Community friends!  For those who don't know me, I'm a product marketer on the Confluence Cloud team - nice to meet you! For those of you who do, you know that I've been all up in your Co...

543 views 7 6
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