I have encountered many scenarios where clients have required an autonumber on an entity. For example they needed to generate a customer number on an account or a quote number etc. There are a number of ways to generate autonumbers using code usually through plugins. You can find a create example of autonumber code here. Today I’ll take you though how to create an autonumber solution using standard Microsoft CRM Workflow with no coding required.
First create a new entity called “Auto Number” to store the next available number for your autonumber. Next create single integer attribute called next number and place that on your form. Now you will need to create a 1:n relationship to the entity where you want to use the Autonumber. In my example I’ve created an 1:n relationship to the account entity. Ensure you can access your new entity from the settings area and publish your changes. Navigate to your new entity and create a record as shown below. I’ve called my record “Account Auto Number” and I’ve set my next number to 1.
Next create a new integer attribute on the entity where you want to the auto numbering to occur. In my example I’ve created an attribute called Customer Number on the Account Entity.
The next step is to create the workflow against, in my case, the account entity. The workflow will be started on the creation of a new account. Create the following steps in your workflow:
- Your first step in your workflow will be an update to the Account. In the Update Account screen select the additional fields tab and find the auto number lookup field created when you created your 1:n relationship. Click on the look up and select “Account Auto Number”
- Next create another update to the account step in your workflow. It is important to do this as a separate step as you need to link your account to the “Account Auto Number” record first. In your Update Account screen set your Customer Number field to be a dynamic value. Set your look for to your Auto Number entity and select the Next Number as the field.
- Lastly we need to go back and increment the next available customer number by 1. To do this create a new update step. This time you will be updating the Auto Number Entity. In the Update Auto Number field increment the Next Number by 1.
Publish your workflow and that’s it :)
There are a few things to note in using a workflow rather than a plugin to generate a auto number. Firstly a workflow is asynchronous and thus a user will not see the next number update immediately after saving the record. They will need to wait until the workflow has run and re-open the record. Also workflows do not run offline so the user will need to wait until they go online to generate a auto number.
30 comments:
great blog - i'm keen to try this so very happy to find it accessible on the net.
Matt, Melbourne
Hi Matthew,
Glad you found this useful. I've used this solution in several of my clients and they love the flexibility that it gives them.
this not warranty the unique number, if you create more than one account in the same time maybe get the same number.
hi, finally got around to implementing, and finding the number keeps doubling ie we get 1,2,4,8,16 etc. heard of this before? pretty sure we followed it exactly?
I've realised why now. in your last step, you are saying increment the Auto Number byt the value of the Auto number, so your first example will be 'increment the value of 1 by 1', but then your next example will be 'increment your value of 2, by the same value, 2" hence by doubling issue. cant see how this would work at all based on this setup?
Hi Matt,
I haven't looked at this for a while but it looks like I may have described the last step incorrectly. What you want to do is increment the last auto-number by 1 not by the last auto number. From memory you leave the default of 1 but do not put in the auto number field. I'll dig up my solution on a VPC and double check my screenshots and correct the error. Thanks for bringing it to my attention!
Cheers,
Karl
Thanks for the solution. I can now auto generate number. My issue now is the auto number (nvarchar) contains comma in the number. I tried to remove the comma in the system setting by using a space. It looks funny in the form. How do you convert the integer to nvarchar without having to include the comma or space.
You told the solution but still it's dobuling can u post the screen shot or the steps.
If anybody got the answer correctly please help. I am looking forward to a solution.
To make the numbers properly increment by 1, in place of:
"Increment by {Next Number(Auto Number (Auto Number));1}"
you need to use:
"Increment by {1}"
(Select the "Next Number" field, change "Operator:" from "Set to" to "Increment by", type "1" in "Default value:", and then click OK)
Really Found this brill thank you so much, however my number's are still doubleing rather than adding 1 each time. Any ideas I have set the default to 1.
Please see below but it is still doubleing up.
{Next Number(Auto Number (Auto Number));1
Any ideas what I am doing wrong ? the field is set in type int and the workflow is set to user.
thank you so much.
Janet Belfast
Read the comment directly above yours Janet.
I feel so so silly I read it again last night and did a full Homer Simpson duh! The answer was there teh whole time
Got it sorted.
Thank you for writing back.
Your a star
Janet
I'm unable to get this working, is anyone able to assist?
To make the numbers properly increment by 1, in place of:
"Increment by {Next Number(Auto Number (Auto Number));1}"
you need to use:
"Increment by {1}"
(Select the "Next Number" field, change "Operator:" from "Set to" to "Increment by", type "1" in "Default value:", and then click OK)
I must be missing something. How do relate the Account record to the Auto-Number record? When I write the workflow as described, there are no auto-relation between the records.
You'll need to create a 1:N relationship between the Auto-Number record and the Account record.
(Go to Settings > Customization > Auto-Number record > 1:N Relationships > New 1-to-Many-Relationship)
I created the relationship - but the record containing the number is not associated with the account unless I manually link them in the Auto Number record. Change the 1-to-many relationship to Cascade All?
In step 1 of the workflow outlined above, you link the Auto-Number record to the Account record.
(Make sure you have already added the lookup field to the Accunt record- you may need to click publish for it to show up when building the workflow. Then you populate the lookup field in step 1 of the workflow.)
If I am reading this correctly, you have to manually link each account record to the autonumber record for the workflow to work?
No. When you set up the workflow, you manually link the workflow to the autonumber record.
Then the workflow automatically links each account record to the autonumber record.
Will this result in duplicates on occasion?
It will not generate duplicates, because MS CRM workflows are asynchronous.
Whereas a plug-in could generate duplicates if it's synchronous.
This is an excellent solution for auto numbers wihtout going into any programming. I am testing this on CRM 2011 Online.
The solution does create duplicates at times, though, as I have tested. Anyone there who might have figured out a resolution for this? I would appreciate. Thanks.
Thank you for posting this blog.
I have been following your steps but I do not see where I can set my "Account Auto Number" to 1.
When I open the attribute "Account Auto Number" I do not see the screen that you showed on your blog.
I do not know why I am missing this item.
First you create a new entity, then you create a record.
You enter the "1" on the record.
Adding voice to 556264, how can we get rid of the commas that come up when the number goes above 999. we get the values like 1,000 and 1,001 and so on.
Does the above method work on Dynamics CRM 2011 ???
Not for me I tried in CRM2013 online
you just need to use:
"Increment by {1}".never adding nothing.its running well
Post a Comment