Auto Number generation using Real Time Workflow in MS CRM 2013

Auto Number generation using Real Time Workflow in MS CRM 2013

Hi All,

I am going to show you the example of Real Time Workflow for Auto Number generation.Follow the below steps to create Auto Number for Contact entity,

Step 1: Create a Custom Entity “Counter” with the following Fields

Counter Value: Whole Number (Range as required)

Step 2: Create One Record in Counter entity as follows,

Counter Entity

Step 3: Create N:1 relationship between Contact to Counter entity as follows,

Contact to Counter realtionship

Step 4: Create “Contact ID” field in Contact entity as follows,

Contact Id field creation in Contact Entity

Step 5: Place “Contact ID” and “Counter_Contact” fields on the Contact entity form and hide them,

Contact Form

Step 6: Create a Real time workflow as follows,

Workflow Wizard
Workflow Creation

Step 7: Create a step to Update “Counter-Contact” record in Contact entity as follows,

Workflow Step 1
Workflow Step 1.1

Step 8: Update Counter Value from Counter entity as follows,

Workflow Step 2
Workflow Step 2.1

Step 9: Update Counter Value by 1 in Counter entity

Workflow Step 3
Workflow Step 3.1

Step 10: Activate the Process and Create Contact Record

Auto Number Generation

Please provide your valuable comments.


58 thoughts on “Auto Number generation using Real Time Workflow in MS CRM 2013

  1. Great Article! I’ve been thinking about doing this for a customer who wants to generate a “record id” for Accounts. However, they want their number to start with 320001. In CRM, whole numbers appear as 320,001. I don’t want that comma in my record id. Any thoughts on that?


      • Hi Arun – Actually, I tested this a bit more and no need for a jscript! In my CRM Admin User Preference, I can change my Number formatting to NOT have commas. Then, I just have the workflow run in context of the owner of the workflow (the CRM Admin). When I update the Customer ID text field, there is no comma! So we are good to go! Thanks again for the article!


      • That is a good point, it does indeed change the format of currency fields too. However, in this case it is ok. It is a personal setting that I changed just for a CRM User we have that is for administration only. So in this case, I don’t care how those currency fields appear to this seldom used CRM User.


  2. I do not even know how I ended up right here, however I believed this put
    up was once good. I do not realize who you are but definitely you are going
    to a well-known blogger when you are not already.


  3. That is really fascinating, You are an overly skilled blogger.

    I have joined your feed and look ahead to seeking extra of your fantastic post.
    Also, I’ve shared your web site in my social networks


  4. Hello there, just became aware of your blog through Google, and found that it’s truly informative.
    I’m going to watch out for brussels. I will appreciate if you continue this in future.
    Many people will be benefited from your writing.


  5. Nice simple Idea so simple then again the best ideas usually are.

    Have you tested this with imports or multiple users adding records at the same time?



  6. Prefty nice post. I just stumbled upon your weblog
    and wanted to say that I have really enjoyed surfing around your blog posts.
    After all I’ll bee subscribing to your rss feed and I hope you write again soon!


  7. Hello Arun,

    you did a great job, however it failed when i’m doing migration of data all at one go. I tried to make it on-demand workflow and run it. I duplicated the id’s. I only works when you create one by one.



  8. Thanks for the information 🙂

    Can you please help me on this: filtration of options on the basis of value selected.
    like if i have to select between ice cream & soft drinks, if i have selected ice-cream then i only related options will be visible.


  9. Hi Arun,

    Thanks for your solution

    Just a question: how can I be sure that when two person are creating a contact at the same time there will be two different ID?



    • Hi Sylvain,

      We can be sure of it because all the steps in this synchronous workflow will happen in single database transaction. So it won’t allow same ID counter to be updated to 2 records at any time.



  10. Hi Arun,

    I am using 2016 trial account. I followed the exact way you have mentioned above to generate an auto-number. But I am not getting it. Could you help please.


  11. Wow, incredible blpg layout! Ꮋow lоng have you beеn blogging fοr?

    үоu maҝᥱ blogging look easy. TҺe overɑll ⅼooк of your sie iis magnificent, as well
    ass thе content!


  12. Hi, Is it possible to add a generic prefix to the number? I.e I need the same three letters to appear before the auto generated numbers?


  13. Arun great article to bring to the masses. How do you deal with duplication of auto numbers when two users save at the same time? I had thought that workflows would not run up against one another when dealing with the same entity (such as locking in C# code) but this is not the case.


    • Hi Jonathon,
      There is no issue with duplicate numbers with this approach. As we are using real time workflows, CRM will lock the table until it process the next one. So, to test this scenario try to import some records using Data Import Wizard and see for any Duplicate numbers.

      Thank You.


      • Hi Arun,

        I did test with user interaction, meaning two users clicking save at the same time. This resulted in duplicate numbers. The exclusive locking did not appear to happen when running the Synchronous workflow.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.