Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 21:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.
×Hello,
I'm attempting to create a ScriptRunner custom script macro by following the example at:
https://scriptrunner.adaptavist.com/latest/confluence/macros/CustomMacros.html#_cql_search_macro
When I enter the macro code from the example, I get the following errors:
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.
Thanks,
Dave
Hi Dave,
Can I see which classes you are importing please?
Thanks
Johnson
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.api.model.search.SearchContext
import com.atlassian.confluence.api.service.search.CQLSearchService
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": content.space.key)
}
}
}
td { p(content.space.name) }
}
}
}
}
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)
view
Thanks for your help.
Dave
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.