Auto numbering in Dynamics 365 Customer Engagement
Auto numbering feature has always been there in the Dynamics CRM application settings, but it was restricted to a few entities such as contracts, cases, articles, quotes, and so on.
If we click Settings -> Administration -> Auto-Numbering option, we can see the auto numbering configuration panel with existing entities as below:
Previously we could configure auto-numbering for some predefined entities such as, Contract, Cases, Articles, Quotes, Orders, Invoices, Campaigns and so on. But in Dynamics 365 we can create Auto-Numbering for all other entities also. We can do this using SDK only there is no visual editor available. Xrm Toolbox has a plugin which can do this using UI.
The below code is the sample code to create a Auto-number in Contact entity.
CreateAttributeRequest createAttributeRequest = new CreateAttributeRequest(); createAttributeRequest.EntityName = “contact”; var autoNumberAttributeMetadata = new StringAttributeMetadata() { //”CUST” is a custom string that we want to prefix with the sequence. //{SEQNUM:size} – Size of the sequence number //{RANDSTRING:size} – Size of the random string to be generated //{DATETIMEUTC:format}- Format for the date time //”new_contactsequence” is the attribute to hold the auto-number AutoNumberFormat = “CUST – {SEQNUM:4} – {RANDSTRING:4} – {DATETIMEUTC:yyyyMMddhhmmss}”, SchemaName = “new_contactsequence”, MaxLength = 100, RequiredLevel = new AttributeRequiredLevelManagedProperty( AttributeRequiredLevel.ApplicationRequired), DisplayName = new Microsoft.Xrm.Sdk.Label(“Customer Sequence”, 1033), Description = new Microsoft.Xrm.Sdk.Label(“This is contact seq”, 1033) }; createAttributeRequest.Attribute = autoNumberAttributeMetadata; var response = organizationService.Execute(createAttributeRequest);The sample sequence will look like : CUST-1000-Y1K1-20200101022119
AutoNumberFormat value | Example value |
---|---|
CAR-{SEQNUM:3}-{RANDSTRING:6} | CAR-123-AB7LSF |
CNR-{RANDSTRING:4}-{SEQNUM:4} | CNR-WXYZ-1000 |
{SEQNUM:6}-#-{RANDSTRING:3} | 123456-#-R3V |
KA-{SEQNUM:4} | KA-0001 |
{SEQNUM:10} | 1234567890 |
QUO-{SEQNUM:3}#{RANDSTRING:3}#{RANDSTRING:5} | QUO-123#ABC#PQ2ST |
QUO-{SEQNUM:7}{RANDSTRING:5} | QUO-0001000P9G3R |
CAS-{SEQNUM:6}-{RANDSTRING:6}-{DATETIMEUTC:yyyyMMddhhmmss} | CAS-002000-S1P0H0-20170913091544 |
CAS-{SEQNUM:6}-{DATETIMEUTC:yyyyMMddhh}-{RANDSTRING:6} | CAS-002002-2017091309-HTZOUR |
CAS-{SEQNUM:6}-{DATETIMEUTC:yyyyMM}-{RANDSTRING:6}-{DATETIMEUTC:hhmmss} | CAS-002000-201709-Z8M2Z6-110901 |