Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal


  • Give kudos
  • Received
  • Given


  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Is there a way to automate the Move page option

I have pages that once completed I would like to move from one location to another location.  And it is always the same location, can I set up a 'MOVE' button on the exiting page to click and it would move the page (and all of its child page too) from current location to the new location?

NOTE: Yes the Move option is VERY simple to use, but I do this action quite often so I just want a button to 'automate' the process.

1 answer

1 vote
Zak Laughton Atlassian Team Jul 23, 2018

Hi Casey!

I was playing around with this, and think I got to the point that's REALLY close. The user macro below will create a button that is intended to move the current page under another page. The problem is, instead of waiting for the button to be clicked, it just moves the page as soon as the page is loaded with the macro.

It seems like the movePageAsChild() method is called as soon as it is read inside the button tag. If someone could find a way to not have it called until the button is pushed, this macro would be perfect! Unfortunately, I couldn't find a way as I was experimenting.

Putting this code here in case it helps you or anyone else on the way to a solution.

(change "65538" to match the ID of your destination parent page)

## Macro title: Move page
## Macro has a body: N
## Body processing: No macro body
## @noparams

#set ($pageManager = $action.getPageManager())

#set ($page = $content.getEntity())
#set ($destinationPage = $pageManager.getPage(65538))

<button class="aui-button" onclick="{$pageManager.movePageAsChild($page, $destinationPage)}">Move page under "$destinationPage.getTitle()"</button>

Did you ever get this to work?

Well the code above works as described.  The page is moved once loaded, but that is not realistic.  It may be worth posting the question about how to prevent the move until a condition is met?  So maybe there could be a checkbox condition on the page that the user has to have checked before it is moved? If the checkbox is not check the code would not move the page, and if the checkbox is checked then reload the page and it will be moved?

Sounds like a valid way to do it - but no matter how I add that movePageAsChild function to a user macro - its triggered instantly when the page is loaded.

There might be some ideas in this examples in the link below of how to put in 'conditions' like a checkbox is checked before move is allowed to happen.

Apologies as I am not of a 'developer's mind' so I am not able to understand how to modify the code to set up a conditional 'if statement'

Zak Laughton Atlassian Team Nov 12, 2019

I've learned quite a bit about Javascript since I made this original post. I have some ideas that might help, but unfortunately, I don't have a Confluence environment still set up to test and confirm.

As I wrote the code in my comment above, Javascript sees the "onClick" value as a function call, not as a function definition, which is why it runs as soon as the button is put on the page. You might be able to fix this by wrapping the function call inside another function. To do this, change the last line to:

<button class="aui-button" onclick="{() => $pageManager.movePageAsChild($page, $destinationPage)}">Move page under "$destinationPage.getTitle()"</button>

Metaphorically speaking, if my original code is handing an instruction card to the button saying "Do this now!", then adding "() =>" before the function call is passing an envelope to the button and saying "In case you get clicked, open this up and follow the instructions on the card inside." (See also: Arrow function expressions).

If that still doesn't work, there's some good discussion here about adding functions inside "onClick": How to call a function onclick and pass arguments.

The only caveat I can think of here being that everything I wrote above addresses how Javascript works on a basic HTML page, while user macros are written with Velocity templates, which might handle these calls differently.

PM me and I can test it in my test environment and post the results once working

Hi @Zak Laughton 

I've tested your suggestion - it still instantly executes the click functionality.


Suggest an answer

Log in or Sign up to answer
Community showcase
Posted in Confluence

What do you think is the most *delightful* Confluence feature? Comment for a prize!

- Create your own custom emoji 🔥 - "Shake for Feedback" on mobile 📱 - An endless supply of GIFs via GIPHY 🤩 Is there anything quite as nice as a pleasant surprise? Comment below with what...

402 views 23 8
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you