Error with ScriptRunner Custom Macro example


I'm attempting to create a ScriptRunner custom script macro by following the example at:

When I enter the macro code from the example, I get the following errors:

Screen Shot 2017-04-20 at 8.24.52 PM.png

I'm on Confluence 6.0.6 and using ScriptRunner 4.3.17.

I'm a newbie, so any help would be very much appreciated. 



1 answer

Hi Dave,


Can I see which classes you are importing please?




Hi Johnson, 

I copied the entire script from the example at the link in my original post pasted it into my script macro, as follows:

import com.atlassian.confluence.api.model.Expansion
import com.atlassian.confluence.api.model.content.Content
import com.atlassian.confluence.api.model.pagination.PageResponse
import com.atlassian.confluence.api.model.pagination.SimplePageRequest
import com.atlassian.confluence.xhtml.api.XhtmlContent
import com.onresolve.scriptrunner.runner.ScriptRunnerImpl
import groovy.xml.MarkupBuilder

def cqlSearchService = ScriptRunnerImpl.getOsgiService(CQLSearchService)
def xhtmlContent = ScriptRunnerImpl.getOsgiService(XhtmlContent)
def maxResults = parameters.maxResults as Integer ?: 10

def cqlQuery = parameters.cql as String

def pageRequest = new SimplePageRequest(0, maxResults)
def searchResult = cqlSearchService.searchContent(cqlQuery, SearchContext.builder().build(), pageRequest, Expansion.combine("space")) as PageResponse<Content>

def writer = new StringWriter()
def builder = new MarkupBuilder(writer)

if (searchResult.size()) {
builder.table {
tbody {
tr {
th { p("Title") }
th { p("Space") }
searchResult.results.each { content ->
tr {
td {
p {
"ac:link" {
"ri:page"("ri:content-title": content.title, "ri:space-key":
td { p( }

if (searchResult.respondsTo("totalSize")) { // confl 5.8+
builder.p("Showing ${Math.min(maxResults, searchResult.totalSize())} of ${searchResult.totalSize()}")
else {
builder.p("No results")

def view = xhtmlContent.convertStorageToView(writer.toString(), context)

Thanks for your help. 


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
Asked Thursday in Confluence

What are the resources that you use to learn more about Atlassian Products?

I am gathering information about resources available for Atlassian product knowledge transferring for a presentation in our local Atlassian User Group. I want to group them in four categories From ...

159 views 5 7
View question

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