How to add a dynamic HTML table to a report email template through DSP customization

If you’re not familiar with Docentric report email templates, you can get started here.

Sometimes we have the need to created a dynamically populated table with a variable amount of rows in our email, like the example below:

And if the table is empty, we would like to hide it, like so:

To add a dynamic table like the above to a report email template, you’ll first need to write a custom DSP class that creates a list of items and the HTML that creates the table.

In this post we’ll show an example written for the salesConfirm report:

class DocSalesConfirmDSP_HtmlPlaceholders extends DocSalesConfirmDSP
    str itemListLinesHtml;

    public ClassDescription description()
        return 'Sales Confirm DSP with HTML placeholders';

    protected void onSelectedRdpTableRecord(Common _rdpTableRecord, TableName _rdpTableName)
        super(_rdpTableRecord, _rdpTableName);

        if (_rdpTableName == tableStr(SalesConfirmDetailsTmp))
            SalesConfirmDetailsTmp line = _rdpTableRecord;

            itemListLinesHtml += (itemListLinesHtml ? '\n' : '') + strFmt(
        </tr>', line.ItemId, line.Name, line.Qty);

    // List of defined custom placeholders for the report:

    [DocPlaceholderAttribute('ItemList', 'SO - Item list')]
    public DocPlaceholderManager overrideReportRunSettings(DocReportRunContext _reportRunContext, boolean _replaceStandardPlaceholders = true)
        DocPlaceholderManager placeholderMng = super(_reportRunContext, _replaceStandardPlaceholders);
        if (_reportRunContext.parmPrintDestination() == DocPrintDestination::Email)
            DocPrintDestSettingsEmail emailPrintDestSettings = _reportRunContext.emailPrintDestSettings();

            str itemListHtml;

            // replace HTML placeholder @ItemList@ with HTML table
                itemListHtml = strFmt(
                    @'<table id="item-list">
                                <td class="header-cell" style="min-width: 70px;">Item number</td>
                                <td class="header-cell" style="min-width: 200px;">Product name</td>
                                <td class="header-cell" style="min-width: 50px;">Qty</td>
                    </table>', itemListLinesHtml);
            emailPrintDestSettings.parmEmailBody(placeholderMng.replacePlaceholderInText(emailPrintDestSettings.parmEmailBody(), #ItemList, itemListHtml, false));

        return placeholderMng;


Then we need to select the newly created DSP class for our report:

And finally we would just need to create the appropriate report email template:

That’s all that is needed for creating a dynamic table in your report email template!