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

usermacro - get published date of page version

Rick Rokosch March 17, 2021

Hi there,

I try to create a usermacro for tagging pages with published version and timestamp from publishing. I have found the needed data in "Page History":

image.png

so my macro is look like that:

## @noparams
#set( $version = $content.version )
#set( $dateFormatter = $action.getDateFormatter() )
#set( $date = $content.getLastModificationDate() )
<strong>Version: </strong>$version, <strong>Ver&ouml;ffentlicht: </strong>$dateFormatter.formatGivenString("dd-MMM-yyyy hh:mm", $date)

problem is that the $date is always show that what the name says: the last mod date

In that example timestamp 08:04 instead of 07:48 ... version is matching so if there are unpublished changes I see the correct version but not the correct timestamp:

image.png

Anybody out there with a nice hint for get the correct published date?

1 answer

1 accepted

0 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.
March 18, 2021

Hi @Rick Rokosch 

I tried your user macro, because I was sceptical, that you get "12" for the version. What you do ist, get the version from the $content. And this will always return the latest version, So I do not understand, why this is "12" for you.

When I use this macro, it's always my last version. 

The other thing I'm asking myself: What do you want to achieve? 

The last version published is always the last version in the page history. An unpublished page isn't listed in the page history and will not be displayed. 

Can you try to explain your need again?

Wenn es für dich einfacher ist, kannst du auch in Deutsch deinen Wunsch erklären :) 

Thanks and regards, Dominic

Rick Rokosch March 18, 2021

Hi Dominic,

we (our management) use "comala document control" to get confirmations of readed pages. Now they get the condition to make the reader visible which version of the page he is reading and acknowledging. 

So we have the case that one page (published) is requestet for readacknowledge at a range of days and in that range the pagecontent will be changed by management (unpublished hanging in comala plugin workflow). That changes the lastmodificationdate.

The published state is not equal publish in confluence. I think it is a layer of histroy pages managed by comala plugin.  

The macro  should show the reader the published version and timestamp. So what I need is something like $content.getHistoryVersion($version).getLastModificationDate().

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.
March 18, 2021

Hi @Rick Rokosch 

Oh, okay, I see. So I will not be able to reproduce this without this plugin :)

What I can offer you is a method, where you can get all versions:

On a $page, you can call getVersionHistorySummaries().

Then you can loop over the histories like this:

#set( $childVersions = $pageManager.getVersionHistorySummaries($page.getEntity()) )
#foreach( $childVersion in $childVersions)
#set( $modDate = $childVersion.getLastModificationDate() )
#end
#end

Perhaps, this will help you.

Rick Rokosch March 19, 2021

Yes sir ! Great work ! That was what I am looking for: 

## @noparams
#set( $version = $content.version )
#set( $dateFormatter = $action.getDateFormatter() )
#set( $i = ($pageManager.getVersionHistorySummaries($content.getEntity()).size() - $version) )
#set( $childVersion = $pageManager.getVersionHistorySummaries($content.getEntity()).get($i) )
#set( $date = $dateFormatter.formatGivenString("dd-MMM-yyyy hh:mm", $childVersion.getLastModificationDate()) )

<strong>Version: </strong>$version, <strong>Ver&ouml;ffentlicht: </strong>$date

 I dont know why he needed the content entity instead of page entity but try and error was get the correct result.

Thanks a lot @Dominic Lagger :-)

Like Dominic Lagger likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events