Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

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
atlassian, confluence whiteboards, whiteboard templates, template contest, visual collaboration, atlassian learning, confluence community, brainstorming tools, agile planning, team productivity, confluence templates, share your template

Share Your Confluence Whiteboard Template for a Chance to Be Featured in the Product! 🏆

Want to leave your mark on Confluence? One winner will have their whiteboard design added into Confluence for all users to access! This is your chance to showcase your creativity, help others, and gain recognition in the Confluence community.

Share your template today!
AUG Leaders

Atlassian Community Events