Administration Functions

Copy Space

This script allows you to make a complete copy of an existing space.

This data will be copied:

  • Space description

  • Theme, including any custom content and style sheets

  • All content, including attachments, and comments

  • Space templates

  • Space permissions

What is not currently copied:

  • Page and comment likes.

To use, just provide space to copy from, and target key and name.

Add/Remove Restrictions to Parent & Child Pages

This script allows you to change the restrictions of multiple pages at once. By selecting a parent page you’ll apply all the restrictions to that page and all of its descendants.

The three restriction levels are:

  • No restrictions (Allows everyone to view and edit)

  • Editing restricted (Allows everyone to view, but only some people can edit)

  • Viewing and editing restricted (Allows only some people to view and edit)

For the "editing restricted" and "viewing and editing restricted" options you will need to specify the user group/s or specific user/s that the restrictions will apply to.

When you run the script it will apply these restrictions both to the selected page and all ancestors of this page.

This feature does not override the confluence permission hierarchy, this means that even if you change the permission of a page or set of pages, if an ancestor of that page has a higher level of restriction, the ancestors restriction will be observed.
Read more about page restrictions in the Confluence Page Restrictions documentation.
add restrictions
  1. A page "Banana" has a child page "Tiny Banana".

  2. The "Banana" page has the restriction level of "viewing and editing restricted" applied to only user "bob",

  3. You then use this script to apply "no restrictions" to "Tiny Banana".

  4. The result will be that Bob can’t view the "Tiny Banana" page, as the "Tiny Banana" page has inherited the "viewing and editing restricted" restriction level of "Banana"

Bulk Delete Attachments

If there are many attachments to be removed, it can be very painful to remove them one by one.

This script allows you to delete all attachments, or all attachments older than a selected time period, for a page (or pages).

Bulk Delete Comments from One or More Pages

Comments on pages can become irrelevant, as content changes over time, so it can be sensible to be remove them after a while, which is a tedious task to perform manually.

This script allows you to delete all comments, or all comments older than a selected number of days, for a page (or pages).

Bulk Purge Trash

This script allows you to purge all trash for:

  • One or more specific spaces

  • All spaces

Rename Labels

This script allows the renaming of labels for:

  • One or more specific spaces

  • All spaces

Specify the spaces containing labels that require renaming or tick the checkbox to specify all spaces.

Specify the label name that require renaming.

Specify the new label name.

Label names are not allowed with upper case characters.

Bulk Add/Remove Labels on One or More Pages

This script allows you to add or remove labels on all pages in a page tree.

Specify one or more page trees that require updating.

Specify whether to add or remove the labels.

Specify the labels to be added or removed. Note: For multiple labels separate them with a space.

Change Content Author

This script allows you to change the author of pieces of content, such as pages, blog posts, comments and attachments using a CQL query.

The page history and the last modified author of the content will be preserved. It is only the original Created by author that will be changed.

Clicking the Expand Examples reveals more CQL examples relevant for this script.

A common example is changing all created content from one author to another:

  • The Author is the username of the user you want to change the content to

  • The CQL clause would be:

creator = username

Clear Groovy Caches

Use the Clear Groovy Caches built-in script to manually clear caches if automated clearing fails. Classes should be reloaded whenever a script is modified. However, dependant classes can fail to reload. For example, if you have a custom class file (ClassA) in your script roots and another Groovy script imports that file, modifications to ClassA may not show up until you modify the script that imports them or clear the Groovy cache with this script.

  1. From ScriptRunner, navigate to Built-in Scripts→Clear Groovy Caches.

  2. Click Run to clear the cache.

    clear groovy caches
    Expect a delay in screen refresh as classes are recompiled when clearing caches.

Rename Pages

Allows you to change the titles of the pages selected.

If a root page is selected, the provided transformation will be applied to both the title of the selected page and the titles of all its child pages.

Copy Page Tree

Allows you to copy a tree of pages to anywhere else. If you are copying to a page within the same space, you will need to tell the script how to manipulate the page titles, as titles must be unique within a space. The way you do this is with a groovy closure - three examples are provided.

A use case might be someone that is maintaining product documentation. When a new version of the product is release, they copy the entire documentation pagetree, prepend "v1.0 ".

When the next version is released, they copy the v1.0 tree, but convert v1.0 to v2.0.

Links and image links within the tree of pages you are copying will automatically be updated to reflect any new page titles. So, let’s say you have a link where:

  • "v1.0 Product Doc/Introduction" links to "v1.0 Product Doc/Getting Started"

  • in the copied tree Introduction will link to "v2.0 Product Doc/Getting Started".

To run this you require view permissions on all the pages you are copying, plus edit permission on the target root page.

Inherit Restrictions for Pages

Inherit restrictions lets you create pages inheriting the parent page restrictions. By default, newly created pages only inherit view permissions from the parent page, not edit permissions, which means users have to set it manually every time a page is created. Inherit Restrictions overcomes this shortcoming by offering administrators the option to specify which spaces should inherit page restrictions automatically.

Read more about page restrictions in the Confluence Page Restrictions documentation.
inherit restrictions

To enable space inherit restrictions please select the space or tick the checkbox for all spaces. Creating a new child page in the selected space(s) will inherit both view and edit restrictions from the parent page.

Inherit restrictions considers parent page restrictions and apply the settings to the newly created pages. The feature does not apply cumulative restrictions from all the ancestors of a page.

Prior to upgrading to recent versions of Confluence, your users may often create links in pages to Confluence content by copying and pasting the URL from the browser address bar.

Although this works, you lose features such as incoming links, and if you change the title of a page, any page that linked to it will now contain broken links.

In addition, you lose the ability to change your base URL, or export the space to another instance without breaking those links.

This script will convert these links to the correct internal storage format. If any page has links that are required to be updated, a new page version will be created, allowing you to roll back if necessary.

Links with anchors are also handled correctly. However anchors are notoriously hard to use in confluence, as they also contain the page name. Needless to say, if a link with an anchor did not work correctly before running this script, it will not work after.

The preview will show you which pages and which links are going to be updated.

Your base URL must be set corrrectly for this to work, and must match the full URLs in the pages. If it does not, then they will not appear as candidates for rewriting.
Confluence now includes javascript that will automatically do this for you at the time you paste in the link - but has no effect on existing content. So if you have already upgraded to a recent version of Confluence, you should only need run this script once.

Delete Page Tree

This works around an annoying issue where if you delete a page with child pages, the child pages get moved to the top level of the space.

This script deletes (moves to trash) a page (or pages) and all its children.

Requires remove privileges to each page you are trying to remove. If you don’t have permission to one of the pages, then no pages will be removed.

Switch User

The Switch User built-in script allows administrator users to temporarily assume the identity of another user. Switch User has a variety of uses, such as:

  • Reproducing and troubleshooting problems specific to a user to diagnose permissions issues.

  • Updating an issue on behalf of another user if they are unavailable.

To switch back to the original user, log out and log in again.

XPath Search in Pages

This is an advanced script…​ it searches each pages source using the provided xpath expression. A few example expressions are given.

You might want to use this if you require a high degree of control over the presentation of your wiki pages, and you want to make sure everything is correct.

It’s much more powerful when it comes to searching for structural problems than the Confluence search, however it is much slower. Typically you will only want to run this on a single space. It takes about 1.5 seconds to search a space with 2,500 pages.

You should be reasonably familiar with the Confluence XHTML storage format, and/or be prepared to examine a page’s source with the Confluence Source Editor, in order to work out what expression you need.

Space Statistics

This script allows you to get an overview of your Confluence spaces showing data such as:

  • Number of pages

  • Number of blogs

  • Number of comments

  • Number of attachments

  • Number of likes

  • Number of labels used

  • Distinct number of users that commented

  • Creation date

To use, select one or more spaces from the dropdown list, and press Run.

space stats 1
space stats 2

Configuration Exporter

Use the Configuration Exporter built-in script to export extension configuration information to a descriptor (YAML) file. The YAML file contains information required to configure built-in extension points such as listeners, hooks, macros, and UI fragments, etc.

Using this file within Script Plugins when migrating from one instance to another, allows scripts to be automatically configured, saving time and ensuring consistency across instances.

  1. To create the YAML file, first navigate to Built-in Scripts→Configuration Exporter from ScriptRunner.

  2. Items with configurations available for export are shown in the Export What field. Select the items you wish to generate the YAML for. Multiple items can be exported to one YAML file.


    The Note field is used to distinguish one item from another, only items with notes are shown. Ensure the Note field has a value for all configuration items you wish to export.
  3. Click Run to generate the YAML snippet. Copy the snippet and paste it into your scriptrunner.yaml file.

    You can manually edit the code yourself to add more items, though it’s generally easier to re-generate the YAML file using the Configuration Exporter script.
For more information on using YAML files to create script plugins see Creating a Script Plugin.


CQL Query Condition

Enter a CQL query. This is analogous to a JQL query in JIRA and simple to use if you don’t have a programming background.

A CQL query always returns content. The types of content returned by a CQL query are:

  • Pages

  • Blog posts

  • Comments

  • Attachments

The example CQL query below returns all pages in a particular space which were created by a particular user:

space = KEY AND type = page AND creator = username

More examples are given on the Expand Examples part of each script that uses CQL. To learn more about CQL and how to use it effectively see the official documentation.

Space Administration Functions

The scripts listed below are now available in the "Space Tools" section. These scripts can be used in spaces where the user has space admin permission. Some functionality has been restricted to reflect the lower permission level, but otherwise they operate the same as the original scripts above.

  • Bulk Delete Attachments

  • Bulk Delete Comments for One or More Pages

  • Bulk Purge Trash

  • Bulk Add/Remove Labels on One or More Pages

  • Copy Page Tree

  • Copy Space

  • Delete Page Tree

  • Space Statistics

To access the new space level ScriptRunner section for Confluence, simply navigate to a space where you have space level admin permissions. Click the "Space tools" cog wheel in the bottom left of the sidebar and select ScriptRunner.

Alternatively open the space directory, select the space where you have permission by clicking the relevant "i" icon and then click on ScriptRunner.

sr space tools

Have questions? Visit the Atlassian Community to connect, share, and learn with other Atlassian users and experts, including Adaptavist staff.

Ask a question about ScriptRunner for JIRA, Bitbucket Server, or Confluence.

Want to learn more? Check out courses on Adaptavist Learn, an online platform to onboard and train new users for Atlassian solutions.