Welcome to Zuora Product Documentation

Explore our rich library of product information

Example: Create invoice item nested tables

This topic provides an example of creating nested tables in an invoice to group and display invoice items by charges and rate plans, including detailed steps and merge field configurations.

This example shows how to create three level nested tables with the following layouts on your invoice:

  1. Group the invoice items by charges.
    • Group 1: New Charges. The invoice item charges that are not displayed in the most recently posted invoice.
    • Group 2: Old Charges. The invoice item charges that are displayed in the most recently posted invoice.
  2. For the invoice items in the same charge group, group them by rate plans.
  3. For the invoice items in the same rate plan group, list the following information for each invoice item:
    • Quantity
    • Unit Price
    • Subscription Number
    • Tax Amount
    • Amount Without Tax
The following figure shows the generated invoice:
Generated invoice

Group charge details and subtotals in nested tables

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 3A represents the outer table: InvoiceItem. Insert the following merge fields in this row:
    • Start the outer table: {MERGEFIELD TableStart:InvoiceItem \* MERGEFORMAT}
    • Define a merge field to group by: {MERGEFIELD "NestedTable:GroupColumn InvoiceItem.IsNew" \* MERGEFORMAT}
    • Define a merge field to calculate the subtotal. In this example, it calculates amount without tax: {MERGEFIELD "NestedTable:ValueColumn InvoiceItem.AmountWithoutTax" \* MERGEFORMAT}
    • Define IF field to test the value of the InvoiceItem.IsNew merge field. If the test value is true, display "New Charges". If the test value is false, display "Old Charges": {IF «InvoiceItem.IsNew»="true" "New Charges" "Old Charges" \* MERGEFORMAT}
    • Define a merge field to display amount without tax:{MERGEFIELD InvoiceItem.AmountWithoutTax \* MERGEFORMAT}
    • End the outer table: {MERGEFIELD TableEnd:InvoiceItem \* MERGEFORMAT}​​​​​​​
  • Row 3B represents the nested, outer table: InvoiceItem_RatePlan. Insert a table inside row 3A.
    • Start the outer table: {MERGEFIELD TableStart:InvoiceItem_RatePlan \* MERGEFORMAT}
    • Define a merge field to group by: {MERGEFIELD "NestedTable:GroupColumn InvoiceItem_RatePlanName" \* MERGEFORMAT}
    • Define a merge field to calculate the subtotal. In this example, it calculates amount without tax: {MERGEFIELD "NestedTable:ValueColumn InvoiceItem.AmountWithoutTax" \* MERGEFORMAT}
    • Define a merge field to sort by rate plan rate: {MERGEFIELD "InvoiceItem_RatePlan.RatePlanName" \* MERGEFORMAT}
    • Define a merge field to display rate plan name: {MERGEFIELD InvoiceItem.RatePlanName \* MERGEFORMAT}
    • Define a merge field to display amount without tax:{MERGEFIELD InvoiceItem.AmountWithoutTax \* MERGEFORMAT}
    • End the outer table: {MERGEFIELD TableEnd:InvoiceItem_RatePlan \* MERGEFORMAT}​
  • Row 3C represents the nested, inner table: InvoiceItem_1. Insert a table inside row 3B.
    • First column, start the inner table: {MERGEFIELD TableStart:InvoiceItem_1 \* MERGEFORMAT}
    • Middle columns: No changes required except to update the object name.
    • Last column, reference the Amount Without Tax line item and end the inner table: {MERGEFIELD InvoiceItem_1.AmountWithoutTax \* MERGEFORMAT}{MERGEFIELD EndTable: InvoiceItem_1 \* MERGEFORMAT}​