---
title: "How to automate adding wiki macro to pages"
canonical: "https://support.appfire.com/space/SUPPORT/89137134/How%20to%20automate%20adding%20wiki%20macro%20to%20pages"
format: markdown
---
### Description

If you are migrating from **Confluence 3.x** and want to retain wiki markup on some specific pages, then here is a quick way to do so. The key is knowing what contain you want to retain as wiki markup. Often, pages can be identified by what macros are on the page. The following will use this case as an example, but really any Confluence search terms can be used. 

> ℹ️ **This is for Confluence 3.x only**
> ℹ️ 
> ℹ️ This needs to be done **before** migrating !!!

> ✅ **Be careful, test first**
> ✅ 
> ✅ Whenever using automation that could affect a large number of pages, be very careful and test on a test space or test instance. It is hard to undo most source changes.

> ✅ **Figure out quote escaping for your OS**
> ✅ 
> ✅ See [Tips](https://appfire.atlassian.net/wiki/spaces/CSOAP/pages/68497417).

### References

- [How to globally search and modify content](https://appfire.atlassian.net/wiki/spaces/SUPPORT/pages/89147318)
- [Confluence search syntax](https://confluence.atlassian.com/display/DOC/Confluence+Search+Syntax#ConfluenceSearchSyntax-NOTsearch)

### Dependencies

- [Wiki Markup for Confluence](https://appfire.atlassian.net/wiki/spaces/CWP) - installed on both Confluence 3.x before migration and also on Confluence 4.x/5.x after migration.
- [Confluence Command Line Interface (CLI)](https://appfire.atlassian.net/wiki/spaces/CSOAP)

### Steps

1. Determine your search criteria to find pages. Verify the UI finds the right pages.
  **Example**
2. Construct an appropriate **runFromContentList** command similar to: [How to globally search and modify content](https://appfire.atlassian.net/wiki/spaces/SUPPORT/pages/89147318)
  **Example**
3. Test the **modifyPage** action on a test page
4. Construct the combined command similar to: [How to globally search and modify content](https://appfire.atlassian.net/wiki/spaces/SUPPORT/pages/89147318)
  **Example**

### Alternatives

For people comfortable with SQL and having access to the Confluence database, **runFromSql** can be used as an alternative to find all the pages that need to be modified. There is a **runFromSql** example on [How to automate adding text to Confluence pages](https://appfire.atlassian.net/wiki/spaces/SUPPORT/pages/89147805). Here is some example SQL:

##### **Id of latest version of pages containing search string**

```
select contentid from bodycontent, content 
    where contenttype = 'PAGE' 
        and version = (select max(version) from content as c where c.title = content.title) 
        and bodycontent.body like '%name="table-plus">%' 


```