Getting the Last Entry from Table Data

Scenario

This recipe retrieves the 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

Apps

Reporting for Confluence Server & Data Center, Scaffolding

Level

Easy

Estimated time

10 minutes

Macros

Local Reporter, Report Block, Report Body, Report Info

Suppliers

Collection Supplier

Storage format

You can copy and paste this code into the Confluence Source Editor:

<ac:structured-macro ac:macro-id="42924c1d-db66-49df-95b2-b87117bfe8b2" ac:name="table-data" ac:schema-version="1"> <ac:parameter ac:name="name">mytable</ac:parameter> <ac:rich-text-body> <table class="wrapped"> <colgroup> <col /> </colgroup> <tbody> <tr> <th>Test</th> </tr> <tr> <td> <div class="content-wrapper"> <ac:structured-macro ac:macro-id="66de7172-45d2-4b01-b014-ab37dc0126ea" 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> </div> </td> </tr> </tbody> </table> </ac:rich-text-body> </ac:structured-macro> <ac:structured-macro ac:macro-id="6b69764d-db31-4462-b974-905a35335f5b" ac:name="report-block" ac:schema-version="1"> <ac:parameter ac:name="atlassian-macro-output-type">INLINE</ac:parameter> <ac:rich-text-body> <ac:structured-macro ac:macro-id="2fe30dfd-a445-43e3-9bf4-4308e35d8ff7" 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> <ac:structured-macro ac:macro-id="c58598b6-0ecb-44b1-8fb3-15ba355bd007" ac:name="report-body" ac:schema-version="1"> <ac:rich-text-body> <h3>Getting the last entry from Table Data macro:</h3> <p> <ac:structured-macro ac:macro-id="30654ce7-436d-4476-b198-54332c3cf2a3" ac:name="report-info" ac:schema-version="1"> <ac:parameter ac:name="">data:mytable &gt; collection:last &gt; data:mytext</ac:parameter> </ac:structured-macro> </p> </ac:rich-text-body> </ac:structured-macro> </ac:rich-text-body> </ac:structured-macro>

Macro structure

You can recreate the example in the editor view:

Steps

  1. Let's start by creating a dynamic table which allows a user to enter data.
    Create a Table Data macro with the name "mytable".

  2. Inside that Table Data macro, create a table with one column and two rows. Like this:

  3. Now create a Text Data macro under the "Test" column.

  4. For the Text Data macro, set the Field Name parameter to "mytext", type to "line", and Content to "text".

  5. Outside the Table Data macro, create a Report Block macro.

  6. Within the Report Block macro, create Local Reporter macro and set the Key to "@self".

  7. Within the Report Block macro, create a Report Body Macro, and type "Getting the last entry from Table Data macro:".

  8. Still within the Report Body macro, create a Report Info macro and set the Key to "data:mytable > collection:last > data:mytext".