Forums

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

How can I get last modified date of a page brought into a Page properties report

Jonathan Seal July 21, 2020

I'm creating a set of pages which each are using the page properties to hold a small table of data such as owner, status etc... and then using another page to hold a page properties report to provide a single view of where all the pages are up to. So far so good.

But I want to include the last modified date in the table and have that also reflected in the page properties report. I came across an article which talks to this: https://confluence.atlassian.com/confkb/how-to-display-modified-page-dates-in-a-table-1005791769.html but this means that every time you add the table into a new page you need to manually select the page that you want to the last modified date to apply to (when I just want it to be set to "this page"). However I don't know the syntax that would achieve that. Any ideas or better ways of doing this?

1 answer

1 accepted

2 votes
Answer accepted
Dominic Lagger
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 21, 2020

Hi @Jonathan Seal 

The user macro is a great way to display the last modification date. You just need this macro:

## This is an example macro
## @noparams

#set( $containerManagerClass=$content.class.forName('com.atlassian.spring.container.ContainerManager') )
#set( $getInstanceMethod=$containerManagerClass.getDeclaredMethod('getInstance',null) )
#set( $containerManager=$getInstanceMethod.invoke(null,null) )
#set( $containerContext=$containerManager.containerContext )
#set( $pageManager=$containerContext.getComponent('pageManager') )
#set( $page = $pageManager.getPage($content.getId()) )

$page.getLastModificationDate()

This macro shows the last modification date of the actual page. 

Regards, Dominic

Jonathan Seal July 22, 2020

Hi Dominic - thanks so much! I've dropped this into a new macro and it brings the correct data through and into the report. :) The only thing that would make this better would be to format the date in a more meaningful way. Currently it comes across as:

2020-07-22 10:18:17.027

I certainly don't need the milliseconds, but would also like it to be formatted

DD-MM-YYYY HH:MM

All other dates in confluence appear along the lines of the second example and I'd like to follow that for consistency.

Is that possible by changing the macro in some way? 

Much appreciated!

Dominic Lagger
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 22, 2020

Hi @Jonathan Seal 

Date handling in confluence user macros is quite hard...

I was not able to get it done. Please see the documentation and perhaps you will get it :) 

Regards, Dominic

Jonathan Seal July 23, 2020

Thanks. I followed the link and went down a rabbit warren but ended up finding a detail which I used to change the last line to:

$action.dateFormatter.formatDateTime($page.getLastModificationDate())

and it seems to have worked. I've also then tidied up the general settings for how dates are displayed so it's more like dd/mm/yyyy and we're good now. Thanks for the help and pointing me in the right direction!

Like Dominic Lagger likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events