Geeks With Blogs
Thorvald Bøe
Every now and then I stumble across this requirement. And every time I seem to have forgotten how to do it, and try various approaches like using a calculated field based on Id, or using a workflow based on the Id.

Bottom line is, at the time of creation, the item Id is not yet set, so you cannot use it, neither from a calculated field nor from a workflow. But with a small workaround, it is possible to make it work in an easy and robust way. After writing this post, I hope I will remember the next time.

First, you need your list, I created one called "TestList". I added an "AutoNumber" field of type number.
Second, you need a second list. I created one called "NumberSeries". I will only use the ID field of this list, so no further customization is necessary.
Third, I you need a workflow. The workflow will run upon creation of list elements in TestList, create a new list element in NumberSeries, and then assign the ID of the newly created item to the AutoNumber field in TestList. 

And voila, you are done!

This is not more robust than it will allow troublemakers to assign random numbers to elements by updating them directly, but it is robust enough that it will give you a new, incremented number for every element you create, even if you delete all elements in either list.

If you need something more robust, or if you need further customization like special formatting, you will need to look to either event receivers or javascript. But for a quick and easy solution, this works nicely.


Posted on Wednesday, January 14, 2015 3:37 PM sharepoint | Back to top


Comments on this post: Build a simple auto increment feature in SharePoint 2013 list

# re: Build a simple auto increment feature in SharePoint 2013 list
Requesting Gravatar...
I followed the steps and got stuck on Create item in NumberSeries
can you walk me thru how to get the Numberof series and Variable: create on the first action.

I was able to do the second action " then Update item in Current Item"

Thank you so much.
Left by Mai Nguyen on Feb 11, 2015 11:26 PM

# re: Build a simple auto increment feature in SharePoint 2013 list
Requesting Gravatar...
Can you elaborate on your problems? You will need SharePoint designer to create the workflow. I created this on SP2013 onprem using sp 2010 workflow engine. It could be slightly different on a 2013 engine/sp online.
Left by Thorvald on Feb 16, 2015 9:59 PM

# re: Build a simple auto increment feature in SharePoint 2013 list
Requesting Gravatar...
can we do it with Nintex workflow? I not have access of designer in my SharePoint.
Left by shahid on Feb 17, 2015 12:42 PM

# re: Build a simple auto increment feature in SharePoint 2013 list
Requesting Gravatar...
I'm sorry, I am not familiar with Nintex workflow. You can download SPD 2013 for free here: http://www.microsoft.com/en-us/download/details.aspx?id=35491
Left by Thorvald on Feb 18, 2015 10:20 AM

# re: Build a simple auto increment feature in SharePoint 2013 list
Requesting Gravatar...
so i can put this column autonumber in a list I have already created. then create another list for the id alone.
Left by debra bell on Apr 18, 2015 8:57 PM

# re: Build a simple auto increment feature in SharePoint 2013 list
Requesting Gravatar...
Hi Debra,
That is quite correct.
The point is that SharePoint itself handles automatic increment on list element ID's, so by creating a new element in another list, you are guaranteed a unique ID on that list element, and hence you can use it as an autonumber in your list.
Left by Thorvald on Apr 20, 2015 3:38 PM

# re: Build a simple auto increment feature in SharePoint 2013 list
Requesting Gravatar...
Is it possible if I want to increment only when the condition is true? because my list contain duplicates and I need the number to make it unique.
Left by Ju on Apr 29, 2015 2:11 AM

# re: Build a simple auto increment feature in SharePoint 2013 list
Requesting Gravatar...
This is perfect. Nice and simple. But for some reason my Update Step (and then assign the ID of the newly created item to the AutoNumber field in TestList) doesn't want to update.

The NumberSeries List update with new entry on creationg, but it doesnt update the AutoNumber column in TestList. Any thoughts....this is quite urgent.

I'm using SharePoint Online Plan 2 with SharePoint Designer 2013.

Thanks
E>
Left by Elzett on May 30, 2015 5:22 PM

# re: Build a simple auto increment feature in SharePoint 2013 list
Requesting Gravatar...
Could you possibly try to add an intermediary step where you assign the NumberSeries:ID to a local variable in the workflow? Then you could write the value to the workflow log or email it to yourself. This might give you a clue why the field is not updating. If it is undefined, you are doing something wrong with the lookup. Also log the NewId field to check that the autonumber record is correctly created. Verify that you are doing the lookup correctly (the screen at the bottom).

Good luck!
Left by Thorvald on Jun 02, 2015 10:14 PM

# re: Build a simple auto increment feature in SharePoint 2013 list
Requesting Gravatar...
I've just checked and my lookup is correct as per your sceenshot. I get the following suspended message in the workflow - have no idea what it means though..

RequestorId: a3137a5c-1b66-3316-0000-000000000000. Details: An unhandled exception occurred during the execution of the workflow instance. Exception details: System.FormatException: Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx). at System.Guid.GuidResult.SetFailure(ParseFailureKind failure, String failureMessageID, Object failureMessageFormatArgument, String failureArgumentName, Exception innerException) at System.Guid.TryParseGuidWithNoStyle(String guidString, GuidResult& result) at System.Guid.TryParseGuid(String g, GuidStyles flags, GuidResult& result) at System.Guid.Parse(String input) at System.Activities.CodeActivity`1.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager) at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation) Exception from activity ParseGuid Assign Stage 1 Sequence Flowchart Workflow.WorkflowXaml_5a02a2cb_a63c_46bf_80c1_0f30446c0d6b
Left by Elzett on Jun 03, 2015 10:46 AM

# re: Build a simple auto increment feature in SharePoint 2013 list
Requesting Gravatar...
It still looks like there is a problem with your GUID somehow.
Could you try assigning the NumberSeries:ID value to a variable and then logging it to see its contents? It should be in the format specified in the error messag "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx". If it is not, then you have the wrong field or there is a problem witht he value.
Left by Thorvald on Jun 10, 2015 2:33 PM

# re: Build a simple auto increment feature in SharePoint 2013 list
Requesting Gravatar...
Thank you, Brilliant! Works Perfect! :)
Left by Frode R on Jul 06, 2015 1:46 PM

# re: Build a simple auto increment feature in SharePoint 2013 list
Requesting Gravatar...
I'm stuck on step 2, "Second, you need a second list. I created one called "NumberSeries". I will only use the ID field of this list, so no further customization is necessary."

When you say ID field, what do you mean? I noticed with SharePoint Foundation 2013 there is no ID field. Do you mean a column labeled ID, but then what would the field type be? Single Line, number.

Thank you for your assistance!
Left by Sarah on Jul 07, 2015 4:20 PM

# re: Build a simple auto increment feature in SharePoint 2013 list
Requesting Gravatar...
Sarah,
the ID field is there, it is a column of type int, the name is simply "ID". It doesnt show up under columns in list settings (most likely because it is a built in column, and there is nothing you can do about it anyway) - but if you go to your view settings you will find it, and you can make it visible (it is invisible by default).

In this solution, you don't need to do anything with the ID when creating the NumberSeries list. The ID is created for you automatically. Later, when setting up the workflow, you will find it when you select the NumberSeries list as your data source.

Good luck! :)
-Thorvald
Left by Thorvald on Jul 08, 2015 4:24 PM

# re: Build a simple auto increment feature in SharePoint 2013 list
Requesting Gravatar...
Hello,

I have been trying to implement this method for a few hours now and would really appreciate your help.

I have done everything as you have stated. The only problem I can think of is my 'Variable: NewId'?

Is there any chance you could quickly explain how you cam to create the 'Variable:NewId' in case I am doing something wrong?

Currently the only result I am getting from the AutoNumber column on my test list is 0.

Thanks in advance,
Sam

Left by Sam on Jul 10, 2015 1:30 PM

# re: Build a simple auto increment feature in SharePoint 2013 list
Requesting Gravatar...
Hello Sam,
I understand your problem, as this step was not very well documented. At the time, I was merely making a note of the steps needed for future reference, I did not anticipate so many comments!

To answer your question, the NewId is a local variable. You need to add a new local variable called NewId using the 'Local variables' button in SharePoint Designer. Furthermore (and herein lies the not-so-obvious part), the variable should be of type 'list element ID' or similar (I only have the norwegian type description in front of me)

I suppose choosing 'int' would also work here. The point is to store the list element ID of the created secondary list element in a local variable, and then use it later for the autoincrement value in the primary list.

Eventually I will try to update the blog post to include more detailed steps. Until then, I wish you good luck!

regards,
Thorvald
Left by Thorvald on Jul 10, 2015 2:08 PM

# re: Build a simple auto increment feature in SharePoint 2013 list
Requesting Gravatar...
Hello Thorvold,

Thank you for your quick reply.

I have completed your above steps, but unfortunately I am still receiving the same results.

The only last detail I think that I have entered wrong is the 'Create Item in Number Series'.

When selecting Number Series please could quickly detail what you entered in to this option.

Much appreciated!

Sam
Left by Sam on Jul 10, 2015 3:02 PM

# re: Build a simple auto increment feature in SharePoint 2013 list
Requesting Gravatar...
Hello Sam,
the "Create Item in Number Series" step is quite simple. You select "Create List Item" from the action menu in SPD. That gives you access to two parameters, target list and output variable. The target list is NumberSeries, and the output variable is the NewId variable (which should be an int, remember?)

In other words, you simply want to create a new list item in NumberSeries list, and then grab the item ID for further use.

You can verify that this is working by adding logging (use "Log to history list" from action menu) and checking that new items are created in the NumberSeries list.

regards,
Thorvald
Left by Thorvald on Jul 17, 2015 10:48 AM

# re: Build a simple auto increment feature in SharePoint 2013 list
Requesting Gravatar...
Hi,
I been searching a lot to find a SIMPLE solution, and this is brilliant. There are many too complex solutions out there! This works perfect in SPD 2013 with SharePoint Online. Also used a document library instead on a list for the "TestList" Thank you!

Just an idea to make it robust, have not yet tried it though. Remove all write/edit permissions for users to the NumberSeries and use an App Step (2013) or Impressionation Step (2010) (Gets full permission) to create the item in NumberSeries and later set the number in the new list/library. What do you think of this?

FYI: Some people have been asking about the first step when creating a new item. I don't think you mentioned, but it is required to set the title field here, for your solution, just choose current item: ID. Then it will pass to the variable you created.

Regards,
Christoffer
Left by Christoffer on Aug 06, 2015 9:28 AM

# re: Build a simple auto increment feature in SharePoint 2013 list
Requesting Gravatar...
Just tried what I suggested above with the robust NumberSeries, removing the permissions for users. Works fine. To enable App Step in SPD 2013 and SharePoint 2013/Online. please see link: https://msdn.microsoft.com/en-us/library/office/jj822159.aspx

Regards,
Christoffer
Left by Christoffer on Aug 06, 2015 2:41 PM

# re: Build a simple auto increment feature in SharePoint 2013 list
Requesting Gravatar...
Hello Christoffer,
thanks for your comments and improvements!
I am happy it worked out :)
Left by Thorvald on Aug 20, 2015 3:06 PM

# re: Build a simple auto increment feature in SharePoint 2013 list
Requesting Gravatar...
need to update in different item not in current item is it possible because in i didn't gave the field but in list am having so its possible for different list item
Left by Hariprasad on Nov 20, 2015 7:29 AM

# re: Build a simple auto increment feature in SharePoint 2013 list
Requesting Gravatar...
Hariprasad,
you want to update a different item in the same list from the workflow. Is that correctly understood?

As long as you can identify the item either by using field values in the current item or by other criteria, there is no limitations from the workflow perspective.

If you could elaborate a little on what you are trying to accomplish, which list item do you want to update and how, then I might be able to guide you further.

regards,
Thorvald
Left by Thorvald on Nov 20, 2015 2:26 PM

# re: Build a simple auto increment feature in SharePoint 2013 list
Requesting Gravatar...
Thovald,
I followed your instructions, all seems ok but I get 0 in the AutoNumber field
Could you please help

Regards
Lila
Left by Lila on Dec 12, 2015 6:49 PM

# re: Build a simple auto increment feature in SharePoint 2013 list
Requesting Gravatar...
In Stage:Stage1 of the workflow, how was NumberSeries defined? When I create the workflow, the default is "this list".
I am not very workflow savvy, so your help would be greatly appreciated.
Left by Mike on Jun 07, 2016 5:38 PM

# re: Build a simple auto increment feature in SharePoint 2013 list
Requesting Gravatar...
Hello Mike,
the NumberSeries is just a custom list created with default settings. Simply create a new custom list, name it NumberSeries (or anything other you like) and it should appear in your workflow.

Good luck! :)

-Thorvald
Left by Thorvald on Jun 09, 2016 11:56 AM

# re: Build a simple auto increment feature in SharePoint 2013 list
Requesting Gravatar...
Dear Thorvald,

I have same issue than Sam. AutoNumber in TestList is always 0.
I create variable but Nothing is changing.
Could you please help me ?
-Arnaud
Left by Arnaud on Sep 21, 2016 12:52 PM

# re: Build a simple auto increment feature in SharePoint 2013 list
Requesting Gravatar...
Dear Thorvald,

I have the same issue as Sam and Arnaud.

Thank you,
Left by Justin on Sep 27, 2016 10:26 PM

# re: Build a simple auto increment feature in SharePoint 2013 list
Requesting Gravatar...
I also had the result as 0 when I initially did mine but here's how I fixed it:

Action: "then Update item in Current Item"
List: Current Item

When you modify your AutoNumber field, supply the following:
Set this field: AutoNumber
To this value: (click fx)

Opens a new window for "Lookup for Single line of text"
Data source: Workflow Variables and Parameters
Filed from source: Variable: NewID
Return field as: As String
Left by kilkol on Jan 25, 2017 3:51 AM

Your comment:
 (will show your gravatar)


Copyright © Thorvald Bøe | Powered by: GeeksWithBlogs.net