Auto numbers or unique alphanumeric strings are usually needed by CRM users to uniquely identify records in UI. We have developed plugins in the past, which would generate unique identifiers for us by using counters or random strings.

Microsoft has released an “Auto number” attribute in the 9.0 version of Dynamics 365. Adding the attribute from UI is not allowed yet, but it will be soon. Until then, we can add the attribute via API.

Let’s add one.

1. Create a console application in Visual Studio.

new auto number

2. Add the Dynamics 365 V9.0 dlls as references. Currently, the preview version of the dlls is available in NuGet.

3. Create a connection to your organization and call the CreateAutoNumberAttribute function from the Main() function.

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Configuration;

using Microsoft.Xrm.Sdk;

using Microsoft.Xrm.Sdk.Query;

using Microsoft.Xrm.Sdk.Client;

using Microsoft.Xrm.Sdk.Messages;

using Microsoft.Xrm.Sdk.Metadata;

using System.ServiceModel.Description;

void Main(string[] args)


string orgServiceUrl = ConfigurationManager.AppSettings[“orgServiceUrl”];

string userName = ConfigurationManager.AppSettings[“username”];

string password = ConfigurationManager.AppSettings[“password”];

Uri oUri = new

//** Your client credentials

ClientCredentials clientCredentials = new

clientCredentials.UserName.UserName = userName;

clientCredentials.UserName.Password = password;

//Create your Organization Service Proxy

OrganizationServiceProxy _serviceProxy = new





CreateAutoNumberAttribute(“account”, “new_accountnumber”, _serviceProxy);


4. Following function creates an auto number attribute of “string” type in “Account” entity.

“AutoNumberFormat” is the new property that has been added to the AttributeMetadata class to help us add the auto number attribute.

void CreateAutoNumberAttribute(string entityName, string attributename, OrganizationServiceProxy _orgServiceProxy)


CreateAttributeRequest newAttributeReq = new


EntityName = entityName.ToLower(),

Attribute = new


AutoNumberFormat = “ACC-{RANDSTRING:6}”,

LogicalName = attributename.ToLower(),

SchemaName = attributename.ToLower(),

MaxLength = 150,

RequiredLevel = new

FormatName = StringFormatName.Text,

DisplayName = new Microsoft.Xrm.Sdk.Label(“Account Number”, 1033),

Description = new Microsoft.Xrm.Sdk.Label(“Unique alphanumberic number for each account”, 1033)





5. Time to check out the new attribute!

new auto number

6. Let’s create few accounts and check the auto numbers!

new auto number

7. 9.0 version of Dynamics 365 supports the following tokens for Auto numbers:

Static String

There you have it! We’re happy to have this feature added to Dynamics 365. Be sure to check out our blog for more updates, news, and tips for Dynamics 365!

Happy Dynamics 365’ing!