Using Load from Custom records option on additional attachments

class DocPurchPurchaseOrderReportDSP_CustomRecordsAdditionalAttachments extends DocPurchPurchaseOrderReportDSP
{
    public ClassDescription description()
    {
        return 'Purchase order DSP with additional attachments from custom records';
    }

    /// <summary>
    /// Resolve the underlying attachment record according to the provided _currentAttachmentDefinition.parmLoadFrom().
    /// </summary>
    /// <param name = "_reportRunContext">Report run context</param>
    /// <param name = "_currentAttachmentRule">Report attachment rule</param>
    /// <returns>Underlying attachment record</returns>
    protected Common resolveReportAttachmentRecord(DocReportRunContext _reportRunContext, DocReportAttachmentRule _currentAttachmentRule)
    {
        // If a _currentAttachmentRule is CustomRecords we need to select and return a EcoResProduct table buffer
        if (_currentAttachmentRule.parmLoadFrom() == DocReportAttachmentLoadFrom::CustomRecords)
        {
            EcoResProduct ecoResProduct;
            PurchLine purchLine;
            InventTable inventTable;

            select ecoResProduct
                exists join inventTable where inventTable.Product == ecoResProduct.RecId
                exists join purchLine where purchLine.ItemId == inventTable.ItemId && purchLine.PurchId == purchTable.PurchId;
            
            return ecoResProduct;
        }
        else
        {
            return super(_reportRunContext, _currentAttachmentRule);
        }
    }

}

After adding this class you need to set it as the used DSP class in the reports table, like this: