Printing Invoice to Sales Order Attachments

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.

Unlike the built-in File print destination, when using Docentric you can output reports in batch, e.g. save them to Azure storage, SharePoint or Attachments.

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.

Docentric replica of the Customer Invoice report already implements this feature, alongside the custom placeholders such as Sales ID, Customer account number, Customer name, Customer contact name, Due date, etc.
See how custom placeholders can be used in all Docentric print destinations >>
You can use Docentric replicas of the most commonly used SSRS reports, even if you are using Free Edition. They provide custom placeholders and the proper context execution record for these reports out-of-the-box. See which replicas we cover >>

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.

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 >>

in case that you are using Free Edition please note that the Use only print destinations option of the registered SalesInvoice report design in Docentric report setup should be turned on.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Docentric respects your privacy. Learn how your comment data is processed >>

Docentric respects your privacy. Learn how your comment data is processed >>