You can use Docentric File print destination to output reports to Attachments of the underlying entity, i.e. the context record of the executing report.
What if saving to Attachments fails
If you turn on the Save to Attachments flag and run a report that doesn’t have the context execution record, e.g. the Customer Account Statement report, you will get an error message saying that the context (calling) record of the executing report does not exist or it hasn’t been provided to the report controller.
In Docentric AX framework a context execution record is inferred from the controller’s args.record() value. Thus, in case that there is no underlying record or this record exists but it has not been provided to the executing report controller, you will get the above error message when you try to print a report to Attachments.
For example, exactly this will be the case when you print an invoice to Attachments while posting it. The controller is called without args.record() set to the report execution context record and that’s why there is no underlying entity to attach the printed invoice to. On the other hand, when you print an invoice from the journal, you will not get this error message, because there is a context record, i.e. the controller is called with args.record(currently_selected_record_from_the_journal). In this case the printed invoice will be saved in journal’s Attachments.
What if you want to save an invoice to Attachments of the corresponding sales order each time when you print an invoice to Docentric File print destination with the Save to Attachments option turned on? Is this possible? Yes, it is! And can be easily achieved using a custom Docentric DSP class for the Customer Invoice report.
See how custom placeholders can be used in all Docentric print destinations >>
If using Docentric replicas with Free edition just turn on the Use only print destinations flag for each report in Docentric report setup, to avoid using Docentric replicas’ designs instead of the built-in SSRS designs, since this is the feature provided only by Full Edition.
Writing a custom Docentric DSP class
You can set the context (calling) record of an executing report to an arbitrary record of an arbitrary entity dynamically in X++ by creating and using a custom Docentric DSP (Data Source Provider) class for the report in question.
This affects Save to Attachments feature of Docentric File print destination, and also, it might affect standard placeholders such as %FIELD_XXX% and %METHOD_XXX% used in print destinations.
A custom DSP class is a class that extends the base Docentric DSP class (DocDataSourceProviderSrsReporting), which is also called Default DSP class, and overrides the overrideReportRunSettings() method.
public DocPlaceholderManager overrideReportRunSettings(DocReportRunContext _reportRunContext,
boolean _replaceStandardPlaceholders = true)
DocPlaceholderManager placeholderMng = super(_reportRunContext, _replaceStandardPlaceholders);
// NOTE: If you need to use standard placeholders %FIELD_FieldName% and %METHOD_DisplayMethodName%
// for the changed report execution record, move the following lines of code to the begin of the
// method, before placeholderMng is instanced and remove the wrapping IF statement.
if (_reportRunContext.parmPrintDestination() == DocPrintDestination::File &&
// Change the report execution context to the corresponding SalesTable record.
SalesTable salesTable = SalesTable::find(placeholder_salesId);
// Change the report caption since it will be used as the attachment description.
_reportRunContext.parmReportCaption(strFmt('Proforma customer invoice for the sales order %1', placeholder_salesId));
_reportRunContext.parmReportCaption(strFmt('Customer invoice for the sales order %1', placeholder_salesId));
Learn more about custom DSP classes >>
Assigning a custom Docentric DSP class to a report
First, you need to register the Customer Invoice report design in Docentric report setup and then to assign just created DSP class (e.g. DocSalesInvoiceReportDSP) to it. See how >>
After you create and set this custom DSP class for the Customer Invoice report, each time an invoice is printed to Docentric File print destination with the Save to Attachments option turned on, the output file will be attached to the corresponding sales order.