Report Variable

Description

Defines a temporary variable that can hold data in the current report context.

If used outside a report the value will only last for the current page request. Variables can be overwritten further down the page content, but are each unique to a particular report context. Use in conjuction with the Variable Supplier to retrieve variables for use.


Parameters

NameRequiredAvailable InDefault ValueDescription

Name

 (tick)


The name for the variable. Any existing variable in the same context with the same name will be replaced.

Value

 (error)


Either value or a reporter in the macro body must be specified.

This can be a text value or an %injected% value. If the latter, and the whole value is a single %injection%, the actual value will be stored. If it is a mix of text and injections it will be a text value.

Default Value

 (error)


Either a text value or an %injected% value. This will be used if the value/reporter is empty.


Editor View


Notes

The body can also be used to store a "reporter", such as Local Reporter or Content Reporter. The report results will be cached and can be reused multiple times on the same page. For example, the following will store the list of pages with the "foo" label in descending order as "foo":

{report-variable:foo}
{content-reporter:type=page|label=foo}
  {text-sort:page:title|order=descending}
{content-reporter}{report-variable}

It can then be executed in a report by using Local Reporter:

{report-list}
{local-reporter:variable:foo}

{report-body}{report-info:page:title|link=true}{report-body}

{report-list}

The same "variable:foo" could be used in other reports on the page, and even have additional "sort" or "filter" macros applied.

It can also be used directly in a Report On or Report Info macro and the results iterated over.

Quick Examples

Setting variables to specific values

In conjunction with the Value Supplier, you can set a variable to a specific text, number or even Confluence content value:

{report-variable:a number|value=%value:number 12345%}
{report-variable:a date|value=%value:date(dd-MMM-yyyy) 25-Nov-2009%}
{report-variable:a page|value=%value:content SPACE:My Page%}

Looping variables

You can set variables up to increment through a report loop.

{report-block}
{local-reporter:page:children}

{report-body}
{report-variable:increment|value=%variable:increment > + 1%|default=%value:number 0%}
h4. {report-info:page:title}

*Increment:* {report-info:variable:increment}
{report-body}

{report-block}

Reusing Reporter configurations

The Query Supplier was added in Reporting 3.3.0. Ensure you have upgraded to use this example.

You can store a reporter query as a variable, either to use via Report Info or to execute in a separate report via Local Reporter.

{report-variable:Page Children}
{local-reporter:page:children}
  {content-filter:@self|label=+foo}
{local-reporter}
{report-variable}

Random Foo:

{report-info:variable:Page Children > query:as collection > collection:random|link=true}

All Foo Children:

{report-list}
{local-reporter:variable:Page Children}
  {text-sort:page:title}
{local-reporter}

{report-body}{report-info:page:title|link=true} (Created by {report-info:page:creator|link=true}){report-body}
{report-list}

Tutorial Examples