AX / D365FO – How to Set a Default Restriction Value for Specific Document Types in X++

In Dynamics 365 Finance & Operations, document attachments are categorized using the Restriction field, which determines access control levels. In many cases, businesses require that certain document types always have a predefined restriction value to ensure consistency and compliance.

A common scenario is the need to automatically set the Restriction field to “External” for a specific document type without requiring manual input. This article explains how to achieve this in X++ by extending the DocuRef table and applying the default value logic at the database level.

Solution Overview

The best way to enforce a default restriction value for specific document types is to extend the insert() method of the DocuRef table. This ensures that whenever a new document of the specified type is created, the Restriction field is automatically assigned the correct value without requiring user intervention.

Practical Use Case: Setting “External” as Default for Sales Order Confirmations

In this example, the business requires that sales order confirmation notes always be created with Restriction = External instead of the default Internal setting.

To implement this logic, extend the DocuRef table as follows:

[ExtensionOf(tableStr(DocuRef))]
final class DocuRef_DLXTable_Extension
{
    void insert(RecId _interCompanyFromRecId)
    {
        // Ensure that Sales Order Confirmation documents are External by default
        if (this.TypeId == CustFormletterDocument::find().DocuTypeConfirm)
        {
            this.Restriction = DocuRestriction::External;
        }

        next insert();
    }
}

Leave a comment