Getting the second last entry from Table Data
Scenario
This recipe retrieves the second last row of a Table Data macro when the table is dynamic in size and uses Scaffolding Table Data and Text Data macros in the reporting process.
Result
Recipe
Apps | Reporting for Confluence Server & Data Center. Scaffolding |
---|---|
Level | Easy |
Estimated time | 10 minutes |
Macros | Local Reporter, Report Block, Report Body, Report Info, Report Variable |
Suppliers | Scaffold Data Supplier, Variable Supplier |
Storage format
You can copy and paste this code into the Confluence Source Editor:
<p class="auto-cursor-target">
<br />
</p>
<ac:structured-macro ac:macro-id="99e89354-ca3e-4f20-9afd-d8fefe26ec2e" ac:name="table-data" ac:schema-version="1">
<ac:parameter ac:name="name">mytable</ac:parameter>
<ac:rich-text-body>
<p class="auto-cursor-target">
<br />
</p>
<table class="wrapped">
<colgroup> <col /> </colgroup>
<tbody>
<tr>
<th>Test</th>
</tr>
<tr>
<td>
<div class="content-wrapper">
<p class="auto-cursor-target">
<br />
</p>
<ac:structured-macro ac:macro-id="de37a55c-30ff-47ad-a8d2-529b6f3d9a34" ac:name="text-data" ac:schema-version="1">
<ac:parameter ac:name="name">mytext</ac:parameter>
<ac:parameter ac:name="type">line</ac:parameter>
<ac:parameter ac:name="content">text</ac:parameter>
<ac:parameter ac:name="atlassian-macro-output-type">INLINE</ac:parameter>
<ac:rich-text-body>
<p>
<br />
</p>
</ac:rich-text-body>
</ac:structured-macro>
<p class="auto-cursor-target">
<br />
</p>
</div>
</td>
</tr>
</tbody>
</table>
<p class="auto-cursor-target">
<br />
</p>
</ac:rich-text-body>
</ac:structured-macro>
<p class="auto-cursor-target">
<br />
</p>
<ac:structured-macro ac:macro-id="31238ba3-aefe-485f-b017-a4fa64511744" ac:name="report-block" ac:schema-version="1">
<ac:parameter ac:name="injected">true</ac:parameter>
<ac:parameter ac:name="atlassian-macro-output-type">INLINE</ac:parameter>
<ac:rich-text-body>
<p class="auto-cursor-target">
<br />
</p>
<ac:structured-macro ac:macro-id="5918df0b-de40-468d-b539-bdc458bfc967" ac:name="local-reporter" ac:schema-version="1">
<ac:parameter ac:name="">@self</ac:parameter>
<ac:rich-text-body>
<p>
<br />
</p>
</ac:rich-text-body>
</ac:structured-macro>
<p class="auto-cursor-target">
<br />
</p>
<ac:structured-macro ac:macro-id="1c0bb109-7065-4f26-9d34-87a9dfcd0cee" ac:name="report-variable" ac:schema-version="1">
<ac:parameter ac:name="name">rev</ac:parameter>
<ac:parameter ac:name="value">%data:mytable > reverse%</ac:parameter>
<ac:parameter ac:name="atlassian-macro-output-type">INLINE</ac:parameter>
<ac:rich-text-body>
<p>
<br />
</p>
</ac:rich-text-body>
</ac:structured-macro>
<p class="auto-cursor-target">
<br />
</p>
<ac:structured-macro ac:macro-id="b23a771b-80c3-4d79-8f1f-1950a8ddac08" ac:name="report-body" ac:schema-version="1">
<ac:rich-text-body>
<p>Getting the second last entry from Table Data Macro: <br />
<ac:structured-macro ac:macro-id="e2932c5e-7ae4-4c0a-aa21-1e374e196889" ac:name="report-info" ac:schema-version="1">
<ac:parameter ac:name="">variable:rev > 2 >mytext</ac:parameter>
</ac:structured-macro>
</p>
</ac:rich-text-body>
</ac:structured-macro>
<p class="auto-cursor-target">
<br />
</p>
</ac:rich-text-body>
</ac:structured-macro>
<p class="auto-cursor-target">
<br />
</p>
Macro structure
You can recreate the example in the editor view:
Steps
Let's start by creating a dynamic table which allows a user to enter data.
Create a Table Data macro with the name "mytable".Inside that Table Data macro, create a table with one column and two rows. Like this:
In this example, we used "Cities" as a title for our column but feel free to change it to anything you prefer.
Now create a Text Data macro under the "Cities" column.
For the Text Data macro, set the Field Name parameter to "mytext", type to "line", and Content to "text".
Outside the Table Data macro, create a Report Block macro and tick the Injected parameter.
Within the Report Block macro, create Report Variable macro with the following parameters:
Name:Â "rev"
Value:Â%data:mytable > reverse%Â
Within the Report Block macro, create Local Reporter macro and set the Key to "@self".
Still within the Report Block macro, create a Report Body macro, and type "Getting the second last entry from Table Data macro:".
Still within the Report Body macro, create a Report Info macro and set the Key to "
variable:rev > 2 >mytext"
.