usermacro - get published date of page version
Asked by Rick Rokosch:

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](/t5/image/serverpage/image-id/134870i8BDF375A84517B93/image-size/large?v=v2&px=999 "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](/t5/image/serverpage/image-id/134874i81B0DD34A5F18D22/image-size/large?v=v2&px=999 "image.png")

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


Answers:
author: Dominic Lagger
body: Hi [@Rick Rokosch](/t5/user/viewprofilepage/user-id/4248574)

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

comments: author: Rick Rokosch
body: 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().


author: Dominic Lagger
body: Hi [@Rick Rokosch](/t5/user/viewprofilepage/user-id/4248574)

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()](https://docs.atlassian.com/atlassian-confluence/5.8.2/com/atlassian/confluence/core/ContentEntityManager.html#getVersionHistorySummaries-com.atlassian.confluence.core.ContentEntityObject-).

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.


author: Rick Rokosch
body: 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](/t5/user/viewprofilepage/user-id/601600) :-)


Tags: confluence-server

server

user-macro