MVP Monday - Generating Unique IDs for any Microsoft Dynamics CRM 2011 Entity
Editor's Note: The following MVP Monday post is by Dynamics CRM MVP Gus Gonzales
Generating Unique IDs for any Microsoft Dynamics CRM 2011 Entity
Increasing Out of the Box capabilities of CRM 2011 in a creative way!
I was working on a Project where our customer required a Unique ID to be added to each Opportunity created in Microsoft Dynamics CRM 2011. Opportunities will be created manually sometimes but mostly via data imports so this process had to be accurate as these records will be imported in the thousands and handled by multiple departments and users within our customers company.
I started researching for a solution online for this issue but I couldn't find a single reliable solution that could satisfy the assignment of Unique IDs to thousands of Opportunities created by CSV Import on Microsoft Dynamics CRM 2011 Online.
We started thinking about creating a custom Plug in that would address this issue for our customer but we had some concerns regarding the fact that we were not allowed to lock the server during the operation, so we could not prevent duplicate numbers. With Microsoft Dynamics CRM 2011 On-Prem, we lock the server from the time we query for "what was the last used number" until the time we commit the save so you can make sure that numbers are not repeated.
If only we had access to the awesome Plug In that the Microsoft Dynamics CRM 2011 Team created to Uniquely Identify Contracts, Cases, Articles, Quotes, Orders, Invoices and Campigns…Wait a second - Maybe we can! - Can we?
Yes; well, sort of. An Idea came to my head; I created a Workflow that upon Opportunity Creation it would create an Order (Currently not being used by Microsoft Dynamics CRM 2011 Users), Copy the Order ID to an Opportunity ID field and then Deactivate the created Order.
This solution would provide a Unique ID to the Opportunities seconds after they have been created…for free!
Here are the steps taken to deploy this solution:
- Create an Opportunity ID (text) field and place it somewhere in the form – I chose the Header for extra visibility:
- OPTIONAL: Edit the "Statuscode" of Orders to Specify why the Order was Deactivated:
- Create a Workflow to launch upon Opportunity Creation to Create an Order, Copy the ID and then Deactivate the Order:
Here are the details of this workflow:
-
- On Step 1, create a base Order:
-
- On Step 2, Update the Opportunity ID with the Order ID of the Order you just created on Step 1:
-
- On Step 3, deactivate the Order created on Step 1:
-
- Activate the Workflow.
As Opportunities are created in Microsoft Dynamics CRM 2011, the Workflow will fire up and add the "Opportunity ID" to each Opportunity:
This quick, easy and FREE solution can be applied to any Entity in Microsoft Dynamics CRM 2011 that does not have the Unique ID capabilities Out of the Box.
As an OPTIONAL step, create a Bulk Deletion Job to run periodically to remove the Inactive Orders that were used as Unique ID generators. Here are the steps for that process:
- In CRM 2011, navigate to Settings -> Data Management -> Bulk Record Deletion
- Create a new Bulk Delete Operation that searches for Orders created by the workflow (This operation will run daily for our customer because of the high number of records created daily but it could be scheduled to run weekly or Bi-Weekly):
NOTE: If your Microsoft Dynamics CRM 2011 Users are utilizing the Order entity, you could adapt the steps above to use any of the entities that have access to Unique IDs.
You can also modify the Prefix of the IDs by navigating to Settings -> Administration -> Auto-Numbering in Microsoft Dynamics CRM 2011 specifying the desired prefix for your company:
Enjoy!
About the author
Gus Gonzalez is a Microsoft Dynamics CRM MVP and the SMB Team Lead and Solution Architect at Zero2Ten, Inc. He has over 10 years of consulting experience in the IT Industry, designing and implementing Microsoft Solutions ranging from enterprise to small environments. Worked as a full time Microsoft Certified Trainer from 2005 to 2009 teaching Microsoft Official Curriculum classes regarding Microsoft Windows, Exchange, ISA and SMS Servers along with Citrix, Cisco, EC-Council and CompTIA official curriculum. A Microsoft Dynamics CRM Community Guest Columnist passionate about User Adoption, he often talks about how Brazilian Jiu-Jitsu can be used to Increase User Adoption, sport he practices since January 2010. To learn more about Gus Gonzalez, read his blog or connect via LinkedIn and Twitter.
About MVP Monday
The MVP Monday Series is created by Melissa Travers. In this series we work to provide readers with a guest post from an MVP every Monday. Melissa is a Community Program Manager, formerly known as MVP Lead, for Messaging and Collaboration (Exchange, Lync, Office 365 and SharePoint) and Microsoft Dynamics in the US. She began her career at Microsoft as an Exchange Support Engineer and has been working with the technical community in some capacity for almost a decade. In her spare time she enjoys going to the gym, shopping for handbags, watching period and fantasy dramas, and spending time with her children and miniature Dachshund. Melissa lives in North Carolina and works out of the Microsoft Charlotte office.
Comments
Anonymous
October 03, 2012
Simple & clean use of available architecture. Nice job.Anonymous
October 03, 2012
As maintaining unique id is anyway handled by internal code (CRM internal plug-ins), I think, we should also be able to initiate this using our plug-ins to make it synchronous (if ID generation is required to be synchronous).Anonymous
December 12, 2012
Hello, This seems to solve that issue but does it not prevent that business unit from utilizing the Order piece of CRM and how it can link with Accounts and Opportunities in its original intent? If they did begin using Orders and linking them to Opportunities in a N:1 fashion I could see the owner of the opportunity becoming confused on the fact that the unique identifier for Opportunities and Orders are the same format. But if you foresee that they will not implement the Order feature to its potential then this is a good solution.Anonymous
November 12, 2013
Hello Every one, Can you please help me to solve issue like generate auto-increment unique id on case form like Case ID?Anonymous
February 07, 2014
Great solution! But halfway into building the workflow I realized that I needed a random number generator for Leads. Can you think of a work around since Leads are technically not customers so I was unable to create an order without a contact or account. Thanks!Anonymous
June 17, 2014
Thanks, this is very useful. One suggestion. We can modify Step 1 where Order ID can't be blank. We have to provide some dummy value before we save the workflow step 1 to create Order. Thanks,