Generating a number automatically within Dynamics CRM is one of those requirements asked almost by all clients/projects. We all know that auto-numbering is available out of the box for entities like case, contracts, quote, order, invoice, articles and campaigns, but usually, we have two situations:

  1. Auto-numbering for entities like account, contact, opportunity, etc. (not available in out of the box auto-numbering feature)
  2. Condition wise auto-numbering (business unit wise, category wise)

I am going to demonstrate situation 2 which will give you an idea for situation 1, too.

What You Need

  • A custom entity
  • A Real-time workflow

I am taking an example where I want my accounts to populate ‘account number’ based on ‘account category’. I have also created a lookup field on my account called ‘auto-counter’ which you can see just below category. I have three categories in my account:

  • Direct (DC)
  • Distributor (DB)
  • Secondary (SC)

Auto-Numbering Through Real Time Workflows

What I Want

I want the account number generated to have prefix of category and then sequential 6-digit number. For example, if my account category is direct and I am creating the very first account in Dynamics CRM, then account number must be like DC100001. In your case, prefix can be business unit’s initial. The method remains the same.

Procedure

Create a custom entity with basic field name; other fields to be created would be equal to the number of conditions you have for auto-numbering. In my case, I have 3 conditions that are account category. You might have a situation wherein you want it based on business unit, so you will have to create fields equivalent to the number of business units you have.

Go to settings > Customization > Customize the System.

customize the system

Click on new to create a new entity.

create new entity

You will now have to create records equal to the number of conditions you have. I have 3 categories in account which means 3 conditions and 3 records.

active auto countI have kept the name as DC/DB/SC based on the prefix I want for my account number. Based on my condition, I have filled the fields with DC, DB & SC as 100000 (since I wanted a 6-digit number). Please note that you will have to create separate records for each condition. In the first record I created, I have filled the name DC and field ‘DC’ (whole number) as 100000. Similarly in the second record, I have filled the name DB and field ‘DB’ (whole number) as 100000. In the third record, I have filled the name as SC and field ‘SC’ (whole number) as 100000.

Now we can create a real time workflow on accounts:

create real time workflow

Now we can add steps to this workflow:

add steps to workflow

First of all, I am checking the category of my account. Secondly, I am updating auto-counter lookup field on account with relevant record of category:

update account

Then I am updating my auto-counter record (increment by 1).

update auto count

Then I am updating my account number of account with a combination of name-number of my auto-counter relevant record:

update account with name number

Now if I create an account, account number is generated as soon as I save my record—something like below:

account number is generated

Tips:

  • Please do hide, auto-counter field on form once your workflow starts working.
  • To remove the comma from the Auto-Number field (whole number), copy it to a calculated field of Single Line of Text.

Hope you find this helpful.

Thanks for reading and happy CRM’ing!