Moving a page in AEM 6.5 Groovy script to a Folder | Community
Skip to main content
Level 6
June 3, 2026
Solved

Moving a page in AEM 6.5 Groovy script to a Folder

  • June 3, 2026
  • 1 reply
  • 25 views

Hi,

I need to move a page to a folder in groovy script and it does not work.

Instead of moving the Page to a Folder that exists it moves the page to the same original folder with a name archive1, archive2 etc.

I basically want to write in the groovy script the function tha is the same as the move in the AEM Editor

 Page srcPage = pageManager.getPage(srcPath)
if (!srcPage) {
return buildResult(lineNo, srcPath, destPath, "ERROR", "Source page not found!")
}
def pageName = srcPage.getName()

try {
if (!dryRun) {
pageManager.move(srcPage, destPath, pageName, true, true, null)
}
return buildResult(lineNo, srcPath, destPath, "SUCCESS", dryRun ? "Would be correctly deactivated and moved" : "Deactivated and moved")
} catch (Exception e) {
return buildResult(lineNo, srcPath, destPath, "ERROR", "Move Error: ${e.message}")
}

 

    Best answer by v-lazar

    hi ​@anasustic 

    The second argument of pageManager.move() should be the full target path, including the final page name, not just the parent folder.

     

    So if you pass /content/site/archive and that folder/page already exists, AEM treats the destination path as occupied. Since resolveConflict=true, it resolves the conflict by renaming the moved page to archive1, archive2,...

     

    Build the destination path using the source page name def targetPath = "${destPath}/${pageName}"

    and call pageManager.move(srcPage, targetPath, null, false, false, null)

     

    The third argument is beforeName, which is only used for sibling ordering at the destination. It is not the new page name. Passing null places the moved page at the end.

     

    Also note that shallow=false moves the full page tree. If you only want to move the page content without child pages, use shallow=true.

     

    I would recommend experimenting with resolveConflict=false instead of true, unless you explicitly want AEM to auto-rename the page when a page with the same name already exists in the destination. With resolveConflict=false, the script will fail on conflict, which is usually safer for migration/archiving scripts because it avoids unexpected names like archive1

    1 reply

    v-lazar
    v-lazarAccepted solution
    Level 2
    June 3, 2026

    hi ​@anasustic 

    The second argument of pageManager.move() should be the full target path, including the final page name, not just the parent folder.

     

    So if you pass /content/site/archive and that folder/page already exists, AEM treats the destination path as occupied. Since resolveConflict=true, it resolves the conflict by renaming the moved page to archive1, archive2,...

     

    Build the destination path using the source page name def targetPath = "${destPath}/${pageName}"

    and call pageManager.move(srcPage, targetPath, null, false, false, null)

     

    The third argument is beforeName, which is only used for sibling ordering at the destination. It is not the new page name. Passing null places the moved page at the end.

     

    Also note that shallow=false moves the full page tree. If you only want to move the page content without child pages, use shallow=true.

     

    I would recommend experimenting with resolveConflict=false instead of true, unless you explicitly want AEM to auto-rename the page when a page with the same name already exists in the destination. With resolveConflict=false, the script will fail on conflict, which is usually safer for migration/archiving scripts because it avoids unexpected names like archive1

    https://www.linkedin.com/in/viktor-lazar/ | https://cyber64.com/insights
    anasusticAuthor
    Level 6
    June 4, 2026

    Hi ​@v-lazar 

    Thanks so much for your reply. Yes, this did the trick.

    String targetPath = destPath.concat("/").concat(pageName)
    pageManager.move(srcPage, targetPath, null, true, false, null)