Custom CQL Functions
Using custom CQL functions in ScriptRunner for Confluence allows you to create and share custom CQL functions (values) with your users to empower their search.
For a large instance, some queries could include multiple CQL statements that could get complicated very fast. Creating this custom function would allow your users to use it and perform a basic CQL query.
Create a custom CQL Function
To create a custom CQL function, follow these steps:
The new custom CQL functions will appear here:
And you can use them when performing CQL searches or using the CQL Search Macro macro.
Custom CQL Function example
Return attachments within a specified space
In this example, you'll create a simple CQL function that will return attachments within a specified space. To start, follow these steps:
Once the function is created it's possible to retrieve the output using the ScriptRunner macro CQL Search Macro. Use the query title in spaceAttachments("ds") to retrieve the name of all attachments in the DS (Demonstration Space). You can replace "DS" with whatever your space is named.
Custom CQL Function example with included code
The following examples use code that is included with ScriptRunner for Confluence.
Search page by label
If you create this custom CQL function, you can return all pages that contain a specified label. To set up this CQL function, follow these steps:
Once the function is created, you can use it with the CQL Search Macro macro. A CQL query that you could use with the function is
content in pagesWithLabel("finance") to retrieve all pages with a label in a Finance space, for example. You can replace "Finance" with whatever your space is named.
Return all pages linked to a specific page
If you create this custom CQL function, you can return all the linked pages associated with the specified page. To set up this CQL function, follow these steps:
Once the function is created, you can use it with the CQL Search Macro macro. A CQL query that you could use with the function is content in linkedPages("ds", "Welcome to Confluence"). You can replace the space and title with what is in your instance.
Return all pages using a specific macro
If you create this custom CQL function, you can return all the pages that are using any macro of a specified add-on. To set up this CQL function, follow these steps:
Once the function is created, you can use it with the CQL Search Macro macro. A CQL query that you could use with the function is content in addOnPages("com.adaptavist.confluence.formMailNG").