Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

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,559,048
Community Members
 
Community Events
184
Community Groups

How to execute CQL query in Confluence ScriptRunner?

Edited
zaharovvv_suek_ru
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Dec 25, 2019

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())

 

3 answers

I've gone through quite a few discussions on this and have made two groovy scripts for two CQL query use cases. These can easily be modified as per requirements. 

I know this post was from 2019, but I still think this is very useful. Hi from 2023 👋

 

1. Get values from the title column of a CQL query's results. 

https://github.com/Rinaldi-James-Michael/Atlassian-Public/blob/main/Confluence/Fetch%20Data%20from%20a%20CQL%20query's%20result%20-%20Confluence.groovy

 

2. Add groups to Space permissions of the Spaces returned by a CQL query (this only works if the query contains type=space)

https://github.com/Rinaldi-James-Michael/Atlassian-Public/blob/main/Confluence/Add%20groups%20to%20Spaces%20based%20on%20the%20results%20of%20a%20CQL%20query%20-%20Confluence.groovy

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

0 votes
Roland Holban (Adaptavist)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Jul 23, 2020

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
AUG Leaders

Atlassian Community Events