Based on Option Set Auto Number Prefix Change Using Plugins in Dynamics 365

Based on Option Set Auto Number Prefix Change Using Plugins in Dynamics 365

Auto-numbering is a common requirement in Dynamics 365. However, many organizations need different numbering sequences based on business categories such as Customers, Vendors, Projects, or Service Requests.

Using Dynamics 365 plugins, you can dynamically change the auto-number prefix based on the selected Option Set value and generate meaningful record identifiers.

Business Scenario

Suppose you have a Category Option Set with the following values:

The generated record numbers should look like:

CUST-0001
VEND-0001
EMP-0001

Plugin Registration

Register the plugin on the Create message of the target table.

Retrieve Option Set Value

OptionSetValue category =
(Entity.GetAttributeValue<OptionSetValue>
("new_category"));

int categoryValue = category.Value;

Determine Prefix

string prefix = "";

switch(categoryValue)
{
    case 100000000:
        prefix = "CUST";
        break;

    case 100000001:
        prefix = "VEND";
        break;

    case 100000002:
        prefix = "EMP";
        break;
}

Generate Auto Number

string autoNumber =
prefix + "-" +
sequenceNumber.ToString("0000");

entity["new_autonumber"] =
autoNumber;

Sample Output

Customer  → CUST-0001
Vendor    → VEND-0001
Employee  → EMP-0001
Important: Use a dedicated configuration table or Dataverse sequence management approach to avoid duplicate numbers when multiple users create records simultaneously.

Benefits

Common Use Cases

Best Practices

Key Takeaways