We have had several requests to create unique record IDs for both out of the box entities as well as custom entities. I’ve used jscript, workflows (custom workflow actions) and/or plugins to accomplish the tasks and no two requests are the same.
What I’m going to show is a quick and simple way to get a unique number with an out of the box entity. The entity is question is the case entity. I’ve chosen the case entity because it is one of the seven entities you can use internal auto-numbering. Go To Settings, Administration, Auto Numbering.
The entities available are Contracts, Cases, Articles, Quotes, Orders, Invoices, and Campaigns. We’re going to use Cases. CRM can generate a number for each case. The number is formatted with a prefix, an incremental number followed by a suffix of the length you specify (4 to 6), which are separated by dashes.
Create a new field on the case entity to hold the new record id we’re going to create. The CRM out of the box autonumber field is already defined. Our field is a Single line of Text with a Data type of ”Calculated”. The Calculated field type is new in Microsoft Dynamics CRM 2015.
Click the Edit button next to the Field Type to create the formula. The formula editor is the same editor used in Business Rules. Have a look at Leon Tribe’s MVP Blog regarding some of the formula possibilities.
We’re going to use a simple Trimleft and Trimright to strip out the value.
TrimRight and TrimLeft accepts 2 parameters, the source field and the number of characters to strip out. Our case number is defined as CAS-00001-XXXXXX. The first TrimLeft(Case Number, 4) Strips the prefix from the case number including the dash “CAS-“. The second, TrimRight(), takes the result of the first function and strips the suffix including the dash “-XXXXXX”. The difference in the two functions is the start of the trimming. TrimLeft starts from the left, while TrimRight starts from the right and moves over the number of characters specified. The result is the unique number created by CRM.
I used this example because I’ve heard the out of the box record number isn’t “Pretty.” As a guy, and a tech guy, who works for a Southern California Partner, I don’t understand that statement.
Contact us and we’ll help you incorporate these fields into your business logic.
By Sanford Mosby, Microsoft Dynamics CRM Technical Consultant with xRM3 a Microsoft Dynamics CRM Partner Serving the Customer Relationship Management needs of Southern California, St. Louis and anyone who asks.