User Macro show unpublished pages
Asked by oguz611:

Hi,

i want to check with a user macro, if a page has unpublished changes or not.

my idea is something like this:

#if ( $ContentEntityObject.getContentStatusObject == "DRAFT" )  
\<span class="aui-lozenge aui-lozenge-success"\>YES\</span\>  
#else  
\<span class="aui-lozenge aui-lozenge-error"\>NO\</span\>  
#end

"$ContentEntityObject.getContentStatusObject" isnt working for me with Confluence 7. Do you guys have any ideas for me?

Thanks.


Answers:
author: Dominic Lagger
body: Hey [@oguz611](/t5/user/viewprofilepage/user-id/3878122)

Do you really need an user macro for this?

Out of the box, confluence brings this feature. If the page is an draft, the user who made changes is notified by a box nearby the title:

![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/91604i9B144C8A2D264822/image-dimensions/419x34?v=v2 "image.png")

If some other person go to this site, he won't see the changes. Only if he edit the page, then he will notice, that someone else did some changes.

Regards, Dominic

comments: author: oguz611
body: Hello [@Dominic Lagger](/t5/user/viewprofilepage/user-id/601600)

thank you for your answer. I need that because of administration and organization our confluence pages. We have a big Team and i want to see, on which sites are done last changes and if there are unpublished changes and who has done these changes.

I am a beginner with creating such macros and have build something like this:

## @noparams  
#set ( $descendantPages = $pageManager.getDescendents($content) )

\<table\>  
\<tr\>  
\<th\>Seite\</th\>  
\<th\>Author\</th\>  
\<th\>zuletzt ge?ndert von\</th\>  
\<th\>zuletzt ge?ndert am\</th\>  
\<th\>Entwurf?\</th\>  
\</tr\>  
#foreach ( $page in $descendantPages )  
\<tr\>  
\<td\>\<a href="${req.contextPath}$page.urlPath"\> $page.title \</a\>\</td\>  
\<td\> $page.creator.name \</td\>  
\<td\> $page.lastModifier.name \</td\>  
\<td\> $action.dateFormatter.format($page.lastModificationDate) \</td\>  
\<td\>  
#if ( $ContentEntityObject.getContentStatusObject == "DRAFT" )  
\<span class="aui-lozenge aui-lozenge-success"\>YES\</span\>  
#else  
\<span class="aui-lozenge aui-lozenge-error"\>NO\</span\>  
#end  
\</td\>  
\</tr\>  
#end  
\</table\>

everything works fine, but not the "$ContentEntityObject.getContentStatusObject == 'DRAFT'" part.


author: Dominic Lagger
body: Thanks for sharing more informations. I'm not an absoult expert in user macros, but I created a few and have some examples :)

I thing, your approach isn't possible to do. Because an "unpublished change" ist called a draft. And a draft isn't just a flag to a page. It's a new version.

First of all, if you loop over all pages, you have to check the page and not the "contententtyobject"

```
$page.getContentEntityObject().getContentStatus()
```

But, as I said, this will probably return always "current", because the draft is always current too:

![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/91619i1AD1F6CB6B765415/image-dimensions/518x83?v=v2 "image.png")

There would be an option to show all drafts in a space:

```
#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( $draftManager=$containerContext.getComponent('draftManager') )

<table>
<tr>
<th>Author</th>
<th>zuletzt ge?ndert am</th>
<th>ID</th>
</tr>
#foreach ( $draft in $draftManager.getDraftsForSpace('SPACEKEY'))
<tr>
<td>$draft.getContentEntityObject().getCreatorName()</td>
<td>$draft.getContentEntityObject().getLastModificationDate()</td>
<td> $draft.getContentEntityObject().getId() </td>
</tr>
#end
```

But here, you won't be able to get much more informations like "DisplayName" or "title".

Hope this helped a bit

Regards, Dominic


author: Ran Ever-Hadani
body: I keep forgetting that I have unpublished stuff, and it would be great if I had a list of unpublished doc at top of my overview screen. And for that I need a macro, or at least a deep link that would take me there. At this point the only way to get to the list is via the UI, which sucks.


Tags: confluence-server

macro

server

user-macro