confluence: page properties report macro, method to total/count results?

Gavin Fowler
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.
October 13, 2013

Hi

We're starting to use Atlassians "page properties" & "Page Properties Report" macros in our organisation and my user community is aksing whether it's possible to add a count / totals the results of the "page properties report" display/output (currently it lists all pages but you have to manually count how many results it returns).

Currently, I can see that adding totals is *not* an option within the macro editor, however I'm not sure if there's a change/feature request out there? Does anyone know whether there are alternative methods I can use to generate totals for the "Page Properties Report"? I wondered whether there's any macros/plugins that allow pages counts by page label (i.e. I caould insert the same page label used in the page properties macro).

Any insight/advice welcomed.

Many thanks!

Gavin.

3 answers

1 accepted

2 votes
Answer accepted
Davin Studer
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.
October 13, 2013

Here is a user macro to count pages by label.

## @param Label:title=Label|type=string|required=true|desc=Enter a label to count.

#set( $labelManager = $action.LabelManager )
#set( $labRef = $labelManager.getLabel($paramLabel) )
#set( $pages = $labelManager.getCurrentContentForLabel( $labRef) )

$pages.size()

Gavin Fowler
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.
October 14, 2013

Works perectly Davin! Many thanks for sharing.

Roswitha Gartner December 1, 2013

How can I count pages with a specific page property?

E.g. in this tutorial (https://confluence.atlassian.com/display/DOC/Page+Properties+Macro) the total amount of pages with Current Status "In progress"?

Thanks for any advice/help.

Christian Prestel
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 24, 2014

Hi,
the macro works fine if I use it only one time on a page. But I get an error when used multiple time on the same page.

I work on Confluence 5.4.1

Any ideas? Thank you in advance!

Cause

java.lang.RuntimeException: Error rendering template for decorator root
at com.atlassian.confluence.setup.velocity.ApplyDecoratorDirective.render(ApplyDecoratorDirective.java:186)

caused by: java.lang.RuntimeException: Error rendering template for decorator page
at com.atlassian.confluence.setup.velocity.ApplyDecoratorDirective.render(ApplyDecoratorDirective.java:186)

caused by: org.apache.velocity.exception.MethodInvocationException: Invocation of method 'getWebInterfaceContext' in class com.atlassian.confluence.pages.actions.ViewPageAction threw exception net.sf.hibernate.LazyInitializationException: Failed to lazily initialize a collection at template/includes/menu-macros.vm[line 123, column 92]
at org.apache.velocity.runtime.parser.node.ASTIdentifier.execute(ASTIdentifier.java:223)

caused by: net.sf.hibernate.LazyInitializationException: Failed to lazily initialize a collection
at net.sf.hibernate.collection.PersistentCollection.initialize(PersistentCollection.java:201)

caused by: net.sf.hibernate.HibernateException: collection was evicted

at net.sf.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:3320)

Andrew Kosiarski August 29, 2014

I'm experiencing the same issue - specifically putting 4 or more of this macro on the same page results in the system error

Junio Fernandes
Contributor
April 18, 2018

This code brings items in trash either. For example, I have 61 pages with certain label and this codes brings the number 128 (Confluence 6.4.3).

Like Katya Godneva likes this
Katya Godneva
Contributor
February 6, 2019

Yep, the same issue as @Junio Fernandes.

Like Junio Fernandes likes this
Mario Malagutti
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
February 6, 2019

Sorry guys... I'm removing this useless post.

Junio Fernandes
Contributor
February 6, 2019

That's my answer... I used a colleague account, unintentionally.

I resolved my question counting only pages outside trash. ContentEntityObject has a method that describes the status of the page like "getContentStatus()", or "isCurrent()/isDraft()/isDeleted()".

See: https://docs.atlassian.com/atlassian-confluence/6.4.3/com/atlassian/confluence/core/ContentEntityObject.html

Peter Florijn February 22, 2019

@Junio Fernandes

I have the same problem that the macro count is not correct probably that somewhere a deleted page  is floating around.

can you please share your version of the macro ?

 

Thanks in advance.

PS Team
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 31, 2024

## @param Label:title=Label|type=string|required=true|desc=Enter a label to count.

#set( $labelManager = $action.LabelManager )
#set( $labRef = $labelManager.getLabel($paramLabel) )
#set( $pages = $labelManager.getCurrentContentForLabel($labRef) )
#set( $pageCount = 0 )
#foreach( $pageiter in $pages )
  #if( $pageiter.getType() == "page" && $pageiter.isCurrent() )
    #set( $pageCount = $pageCount +1 )
  #end
#end

$pageCount

0 votes
Andrey Khaneev _StiltSoft_
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.
May 4, 2017

As an alternative you can use Pivot Table macro (Table Filter and Charts add-on) with Page Properties Report macro and count anything you want. Or you can just wrap Page Properties Report macro with Table Filter macro and set row numbering to see the count of pages.

0 votes
Jim
Contributor
May 4, 2017

This works great for me, right out of the box, in Confluence 5.10.8, including using it multiple times on the same page - I tested up to seven lables. Thanks Davin!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events