Get the last entry from a Scaffolding dynamic table

Get the last entry from a Scaffolding dynamic table

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 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. Create a Table Data macro (from the Scaffolding app) with the Name: mytable.
    This macro creates a dynamic table, which allows users to enter data.

  2. Inside that Table Data macro body, create a table with one column and two rows with a header row titled Test.

  3. In the second row, create a Text Data macro (from the Scaffolding app) with the following parameters:

    • Field Name: mytext

    • Type: line

    • Content Type: text

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

  5. Within the Report Block macro, create a Local Reporter macro with Key: @self.

  6. Under the Local Reporter macro, create a Report Body macro with the following text in the macro body:

    Getting the last entry from Table Data macro:
  7. Under the text within the Report Body macro, create a Report Info macro with Key: data:mytable > collection:last > data:mytext.