Conditional Report Attachments Using User-defined Placeholders and Attachment Rules in Docentric AX

Business Scenario

When a Sales invoice is generated in D365FO, the system should automatically attach the appropriate Terms and conditions documents based on the value of the Delivery terms field on the Sales order.

For example, if the Delivery terms value is FOB, the system should attach the FOB Terms and conditions. If the value is CIF, it should attach the CIF Terms and conditions instead.

The user should not need to manually select the appropriate attachment for each invoice.

In this forum-post, “Delivery terms” refers to the D365FO Sales order header field (for example, EXW, FOB, or CIF), while “Terms and conditions” refers to the document that will be attached to the report.

Overview

Docentric AX allows you to automatically attach documents to reports based on business data values, without any code customization. This is achieved by evaluating a field available in the report’s Docentric Data Source Package (DDSP) and selecting the attachment whose tag matches that field value.

This requires the combination of:

  • Standard D365FO Document management attachments
  • Docentric Report attachment loading rules
  • Docentric User-defined-placeholders

In this example, we will configure the Sales Invoice report to automatically attach the appropriate Terms and Conditions according to the Delivery terms specified on the Sales order.

Although this article uses Sales invoices as an example, the same approach can be applied to any Docentric AX report and any field available in the DDSP.

For more information about DDSP files, check out How-To-Manual:
Docentric Data Source Packages (DDSP) Overview
d365-docentric-data-source-packages-ddsp-files-overview

Step 1 - Populate Delivery terms on the Sales order

Open the relevant Sales order and set the required Delivery terms value on the order header. This is the value Docentric will use at execution time to select the matching attachment.

Navigation : Account receivable > Sales orders > All sales orders > select order > Header > Delivery section.

Example: Delivery terms = CIF

Step 2 - Create an Attachment category (Optional but recommended)

For better organization, create a dedicated attachment category if it does not already exist. This step is optional but recommended, as it keeps conditional attachments easy to identify and maintain.

Navigation: Docentric AX workspace > Additional setup > Attachment categories

Create an attachment category named Delivery terms and conditions.

Step 3 - Upload and tag the attachment documents

Open the legal entity attachments, upload each candidate document and mark it as a global attachment. For each document, set the category created in the previous step and populate the Tag field with the corresponding Delivery terms value (for example, FOB, CIF, or EXW).

In our example, tag is the key element Docentric AX uses during the attachment selection step.

Example:

File Category Tag
Terms_Conditions_EXW.pdf Delivery terms and Conditions EXW
Terms_Conditions_CIF.pdf Delivery terms and Conditions CIF
Terms_Conditions_FOB.pdf Delivery terms and Conditions FOB

Step 4 – Create the User-definied placeholder value

Before configuring the attachment rule (next step), confirm that the Delivery terms value is available in the report’s generated DDSP file.

In this example, the value is already exposed under: SalesInvoiceHeader/@MCRDlvTerm

So, no DSP class customization is required, and the relevant solution is to create a User-defined placeholder.

Setting Value
Name DeliveryTerms
Expression SalesInvoiceHeader/@MCRDlvTerm

At runtime, this placeholder resolves to the Delivery terms value stored on the Sales order.

If the desired field is not available in the DDSP, a DSP class customization would be required before continuing.

Step 5 - Configure the Report Attachment Rule

Navigation: Docentric AX workspace → Reports tile → Sales invoice → Print management → Email print destination → Report attachments

Add a new attachment loading rule with the following configurations:

Setting Value
Load from Global attachment
Category Delivery terms and conditions
Tag @DeliveryTerms@ (the placeholder created in Step 4)

Save the configuration.
At runtime Docentric will:

  1. Resolve the placeholder value as the Delivery terms value from the Sales order.
  2. Search for the Global attachments (attachments on current Legal entity having the Global attachment flag set), with Terms and conditions documents category, whose Tag matches the resolved placeholder value.
  3. Attach the matching document automatically.

Step 6 - Test the solution

Generate a Sales invoice for an order with a known Delivery terms value and confirm the correct documents are attached.

Item Value
Sales order Delivery terms CIF
Resolved @DeliveryTerms@
placeholder value CIF
Attachment rule lookup Category = Delivery terms and conditions, Tag = CIF
Result Terms_Conditions_CIF.pdf is automatically attached to the email

This approach can be applied to any field available in the DDSP.

To adapt it:

  • Replace the field referenced in Step 1 with the relevant field on the source document.
  • Update the user-definied placeholder expression in Step 4 to the corresponding Xpath expression.
  • Tag attachments in Step 3 according to the new field’s possible values.

All other configurations including category setup, attachment rule structure, and the tag-to-placeholder matching logic remains unchanged.