Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,369,333
Community Members
 
Community Events
168
Community Groups

How to execute CQL query in Confluence ScriptRunner?

Edited

I have a CQL(Confluence Query Language) query:

код=P

and this query gives me two results:

CQL - confluence query language.png 

How is it possible to execute this code in Confluence ScriptRunner? I mean execute cql query  in Confluence Script Runner like it can be done in Jira ScriptRunner.

 

I've tried to use Jira ScriptRunner code, but Jira code is not working in Confluence Script Runner:

String JqlQuery = "issueType = Epic AND project = HH AND 'Epic Name' = 'epic name'"
def parseResult = searchService.parseQuery(curUser, JqlQuery)
def searchResult = searchService.search(curUser, parseResult.getQuery(), PagerFilter.getUnlimitedFilter())

 

2 answers

Do I understand correctly that these types of queries can not be executed in Cloud?

You can use the `CQLSearchUtils` class for this.

import com.onresolve.scriptrunner.canned.confluence.utils.CQLSearchUtils
import com.onresolve.scriptrunner.runner.ScriptRunnerImpl

def cqlSearchUtils = ScriptRunnerImpl.scriptRunner.getBean(CQLSearchUtils)
def cql = "space = FOOBAR"
def results = cqlSearchUtils.searchForContent(cql)

I tried the same, but getting error message:

groovy.lang.MissingMethodException: No signature of method: com.onresolve.scriptrunner.canned.confluence.utils.CQLSearchUtils.searchForContent() is applicable for argument types: (String) values: [space = AP]
at Script96.run(Script96.groovy:8)

 

Here is the script we tried on the scriptrunner console:

import com.onresolve.scriptrunner.canned.confluence.utils.CQLSearchUtils
import com.onresolve.scriptrunner.runner.ScriptRunnerImpl

def cqlSearchUtils = ScriptRunnerImpl.scriptRunner.getBean(CQLSearchUtils)
def cqlQuery = 'space = AP' // some CQL query
def pages = cqlSearchUtils.searchForContent(cqlQuery)

Any suggestions?

 

Thanks,

import com.onresolve.scriptrunner.canned.confluence.utils.CQLSearchUtils
import com.onresolve.scriptrunner.canned.confluence.utils.CQLSearch
import com.onresolve.scriptrunner.runner.ScriptRunnerImpl

def cqlSearchUtils = ScriptRunnerImpl.scriptRunner.getBean(CQLSearchUtils)
def cqlQuery = 'space = KNOW' // some CQL query
def cqlSearch = new CQLSearch()

def pages = cqlSearchUtils.searchForPages(CQLSearch.fromQuery(cqlQuery))

pages.each{ page ->
log.warn page
}

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events