CQL Escalation Services
Using the CQL Escalation Services built-in job, you can pass the results of a CQL query to the code you provide.
This saves you from writing the code to execute the query and setting the impersonation context.
Components of the job
Script binding
In the script, the binding variable hits is available, which is an Iterable<ContentEntityObject>. Therefore, you can do something with each piece of content returned using:
hits.each { content ->
// do something with content
}Confluence content type information
Depending on your query, the type of content in the above example will be either a Page, an Attachment, a BlogPost, a Comment, or another type of Confluence content. However, it will always be a ContentEntityObject.
If you only want to do something with pages, then use a query that only selects pages like space = "ds" and type = page. Alternatively, you can use instanceof in your script to do different things depending on the type of content. An example is title in spaceAttachments("ds").
Restrictions
Specify a user who has permission to see the content that you want.
Service code
Your service code is automatically wrapped into a transaction template. Make sure that your service doesn't run for a long time, unless it is a quiet time (like the weekend).
To create the job
Follow these steps to create a job where the CQL query passes results to the script, determining where the job's action occurs.
Examples
Add Label to outdated pages
As a worked example, we'll add a label to pages that haven't been modified for one month in a particular space. You may do this if you need to ensure that content is kept current, although this solution is deliberately over-simplistic.
Now, the job will run at 12:30 AM every day and add a label to pages that have not been modified for over four weeks.
Add comment to outdated pages
You can also add a comment to any page that has not been modified for over three months and has had no comments in over three months. To set up this script, follow these steps:
Now, the job will run every Sunday night to add comments to page that have not been modified for over 14 weeks.