Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Is there a way to automate the Move page option

Casey Maynard
Contributor
July 20, 2018

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
Atlassian Team members are employees working across the company in a wide variety of roles.
July 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.

ALMOST-WORKING CODE:
(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>
Henrik Juel Petersen November 12, 2019

Did you ever get this to work?

Casey Maynard
Contributor
November 12, 2019

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?

Henrik Juel Petersen November 12, 2019

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.

Casey Maynard
Contributor
November 12, 2019

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'

 

https://www.codota.com/code/java/methods/com.atlassian.confluence.pages.PageManager/movePageAsChild

Zak Laughton
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 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.

Casey Maynard
Contributor
November 12, 2019

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

Henrik Juel Petersen November 14, 2019

Hi @Zak Laughton 

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

/Henrik

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events