Problem: CQL query returns 1 result, but results is empty when iterating

Alex November 5, 2024
I'm using a CQL query to search for pages with comments created within the last 7 days in a specific space. The query seems to return 1 result based on the log message, but when I attempt to iterate over the results using results.each, the results appears empty.

import com.atlassian.confluence.pages.AbstractPage
import com.onresolve.scriptrunner.canned.confluence.utils.CQLSearch
import com.atlassian.confluence.search.v2.SearchManager
import com.onresolve.scriptrunner.canned.confluence.utils.CQLSearchUtils
import com.onresolve.scriptrunner.runner.ScriptRunnerImpl
import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.confluence.pages.Page;

def cqlSearchUtils = ScriptRunnerImpl.scriptRunner.getBean(CQLSearchUtils)

String cqlQuery = 'space = INFO and type=comment and created >= now("-7d")'

def cqlSearch = new CQLSearch()

Iterable<AbstractPage> results = cqlSearchUtils.searchForPages(CQLSearch.fromQuery(cqlQuery))

log.warn("Find pages : ${results.size()}")

results.each { result ->
log.warn("Page: ${result.title}, ID: ${result.id}")
}

0 answers

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events