Example: Creating a usage nested table
This reference topic demonstrates how to create a usage nested table on an invoice, grouped by custom fields, subtotaled by merge fields, and sorted by charge date.
This example shows how to create a usage nested table with the following layouts on your invoice:
- Grouped by a custom field, Billing Code
- Subtotaled by a supported merge field, Rating Amount
- Sorted in ascending order by Charge Date
The following figure shows the generated invoice:
Group usage details and subtotals in a nested table
To generate the invoice with the above layouts, you need to configure the nested table with the NestedTable:GroupColumn and NestedTable:ValueColumn merge fields. The first column in the table is the legend for identifying the rows.
- Row 3 represents the outer table: Usage. Insert the following merge fields in this row:
- Start outer Table:
{MERGEFIELD TableStart:Usage \* MERGEFORMAT} - Define merge field to group by:
{MERGEFIELD "NestedTable:GroupColumn Usage.BillingCode__c" \* MERGEFORMAT} - Define merge field to calculate the subtotal:
{MERGEFIELD "NestedTable:ValueColumn Usage.RatingAmount" \* MERGEFORMAT} - Define merge field to display the subtotal:
{MERGEFIELD Usage.RatingAmount \* MERGEFORMAT} - End the outer table:
{MERGEFIELD EndTable:Usage \* MERGEFORMAT}
- Start outer Table:
- Row 3A represents the nested, inner table: Usage_01. Insert a table inside row 3.
- Replace the
Usageobject in merge fields in all columns withUsage_01. - First column: Start the inner table:
{MERGEFIELD TableStart:Usage_01 \* MERGEFORMAT} - Middle columns: No changes required except to update the object name.
- Last column: Reference the Rating Amount line item and end the inner table:
{MERGEFIELD Usage_01.RatingAmount \* MERGEFORMAT}{MERGEFIELD EndTable: Usage_01 \* MERGEFORMAT}
- Replace the
- For testing purposes, import the required usage data plus the following fields:
- Usage custom field:
Usage.BillingCode__cor any Usage custom field that you define Usage.RatingAmount
- Usage custom field:
Sort grouped usage data
You can use the TableSort merge field to specify the sorted order for data in nested tables. See Changing the Sort Order on a Table for a detailed explanation of the TableSort merge field.
To sort on a column in a nested table, indicate the sort parameter by choosing the desired nested table column. In the following example, suppose you would like to display items sorted in ascending order by RatingAmount. After the TableStart declaration of nested table Usage_01, insert {MERGEFIELD "TableSort:Usage_01.RatingAmount ASC" \* MERGEFORMAT}. Make sure to use the inner table name (Usage_01 in this example) in the TableSort declaration.
The following shows the inserted TableSort merge field in red.
You can use the TableSort directive in both the outer and inner tables to sort by different parameters.
For example, expanding on the previous example, in which we sorted the inner table on RatingAmount, we will show how to sort the outer table on the custom field BillingCode__c in ascending order. After the NestedTable:ValueColumn declaration, insert {MERGEFIELD "TableSort:Usage.BillingCode__c ASC" \* MERGEFORMAT}. Note the use of the name of the outer table (Usage) in the reference to Usage.BillingCode__c. Because this declaration is in the outer table scope, we must use the outer table name or the template validation will fail.
The following table shows the inserted merge field in red.
The resulting invoice will have a usage table grouped by Usage.BillingCode__c sorted in ascending alphabetical order. Each row will have a nested table sorted by Usage.RatingAmount in ascending numerical order.