Hi Everyone,
This is a common problem faced by lot of guys who has a little programming knowledge. I am going to explain a simple way to crate a auto-increment number column in a custom list without programming. Every time insert an item to the list this will add a unique auto-increment number to column to track the record.
Start out by creating a new column in the SharePoint list you want to have the
auto-increment number in. This must be a number column. Name this whatever you like. The list that i'm using is " Help Desk Tickets" and my column is "Ticket No"
Then create a custom list with any name you want. My one is "Counter".
Counter list has 4 columns Title, Counter, Last Number, Next Number. Title is default Title column. Counter is Single Line of Text column. Last Number is number column and Next Number is a calculated column.
After creating the Counter list I am going to add a new item to the list.
Remember Last Number should be the number BEFORE the one you want to start on. When you added the new item notice the Next Number it now counts +1 from the Last Number.
OK. Then go to the list you are wanting the auto-generated number in, in my case it is "Help Desk Tickets". Open the list in SharePoint Designer. Click "List Workflow" button in the top left corner.
Give a name to the workflow. My workflow is "CounterWorkflow". In the workflow Start Options tick that "Start workflow automatically when an item is created". If you want you can tick "Start workflow automatically when an item is changed" also. It will give a new auto number to changed items too.
Before we start writing the workflow I will create a local variable. To create it click on the "Local Variables" button. Click Add button. Click Name and name it something. I am using "mNumber" as the name and Type is Number.
Click OK. Now you have created a variable called mNumber. This will be used to store our Next Number information so it can be manipulated without actually touching the Next Number fields.
Lets write the workflow.
1. Click on conditions and in common conditions add "if current item field equals value" condition.
In that condition click the "field" and add Title. Click "equals" and add "is not empty".
2. After that click on Actions and in Core Actions add "Set Workflow Variable". Click on "workflow variable" and add "mNumber". Then click on the "value" and click the function button. Select the "Data Source" as "Counter" and "Field From Source" as "Next Number". In "Find the list item section" in message box "Field" is "Title" and type the value as "LTL Folder Number". It looks like following.
When you click on the OK button it will give a warning like this.
Don't worry about it and click on "Yes".
3. Then add another Action. Click on Actions and in List Actions add "Set field in current item". In the action click on "field" and add the number column you want to increment automatically. In my case it is "Ticket Number". Then click on "value" and click on function button. Select the "Source" as "Workflow Variables and Parameters" and "Filed" as your variable. So my field is "mNumber".
4. OK lets add our last action. Click on Actions and in List Actions add "Update List Item". Click on "This List", In the message box select your auto-number list. My one is "Counter". Click "Add" button and select "Set This Field as" "Last Number". Then click on function button in "To This Value".
In the popup select "Workflow Variables and Parameters" as "Data Source" and my variable "mNumber" as "Field from source". You can select your variable.
Then click "OK". Now it looks like this.
Next click on "Field" and choose "Title". Type "Value" as "LTL Folder Number", our new item in the list counter.Now it looks like this.
When you click on the OK button it will give a warning. Don't worry about it and click on "Yes".
We now have a workflow that will pull Next Number from your Counter list. It will then copy it in to the variable and apply the variable to your main list column. Then it will copy the variable back over to Last Number, causing Next Number to increment by 1 or whatever value you choose.
Finally the workflow looks like this.
You have now created a new list and workflow. Now your main list will have a column that auto counts in increments of 1 each time the item is created or based on your conditions.
So now when I add new items to my "Help Desk Tickets", "Ticket No" is auto generated as following.
Have A Nice Day My Friends.
Regards,
Gihan Maduranga.