views:

30839

answers:

21

Hi,

In a SharePoint list I want an auto number column that as I add to the list gets incremented. How best can I go about this?

All the best Kieran

+1  A: 

it's in there by default. It's the id field.

Kevin
+3  A: 

You can't add a new unique auto-generated ID to a SharePoint list, but there already is one there! If you edit the "All Items" view you will see a list of columns that do not have the display option checked.

There are quite a few of these columns that exist but that are never displayed, like "Created By" and "Created". These fields are used within SharePoint, but they are not displayed by default so as not to clutter up the display. You can't edit these fields, but you can display them to the user. if you check the "Display" box beside the ID field you will get a unique and auto-generated ID field displayed in your list.

Check out: Unique ID in SharePoint list

MrHinsh
+11  A: 

Sharepoint Lists automatically have an column with "ID" which auto increments. You simply need to select this column from the "modify view" screen to view it.

BrewinBombers
A: 

Thanks for this.

How about if you need a specific format of unique identifier, any idea's?

All the best Kieran

78lro
You should ask a new question for this, rather than have a discussion in the original question.
Jason Z
+2  A: 

If you want to control the formatting of the unique identifier you can create your own in SharePoint. MSDN also has a visual How-To. This basically means that you're creating a custom column.

WSS defines the Counter field type (which is what the ID column above is using). I've never had the need to re-use this or extend it, but it should be possible.

A solution might exist without creating a custom . For example: if you wanted unique IDs like CUST1, CUST2, ... it might be possible to create a Calculated column and use the value of the ID column in you formula (="CUST" & [ID]). I haven't tried this, but this should work :)

dariom
+1  A: 

If you want something beyond the ID column that's there in all lists, you're probably going to have to resort to an Event Receiver on the list that "calculates" what the value of your unique identified should be or using a custom field type that has the required logic embedded in this. Unfortunately, both of these options will require writing and deploying custom code to the server and deploying assemblies to the GAC, which can be frowned upon in environments where you don't have complete control over the servers.

If you don't need the unique identifier to show up immediately, you could probably generate it via a workflow (either with SharePoint Designer or a custom WF workflow built in Visual Studio).

Unfortunately, calculated columns, which seem like an obvious solution, won't work for this purpose because the ID is not yet assigned when the calculation is attempted. If you go in after the fact and edit the item, the calculation may achieve what you want, but on initial creation of a new item it will not be calculated correctly.

Sam Yates
+1  A: 

As stated, all objects in sharepoint contain some sort of unique identifier (often an integer based counter for list items, and GUIDs for lists).

That said, there is also a feature available at http://www.codeplex.com/features called "Unique Column Policy", designed to add an other column with a unique value. A complete writeup is available at http://scothillier.spaces.live.com/blog/cns!8F5DEA8AEA9E6FBB!293.entry

A: 

Although the "ID" value is not available to be used in a Calculated field, depending on the data, you may also be able to use some sort of concatenation of other fields to create a unique identifier. In particular, the Date fields like Created and Modified could potentially be used for something like this.

Bryan Friedman
A: 

Thanks for the suggestions everyone, I've been looking at the list ID as a potential solution but I see this is only unique within the list, not within the Site Collection.

How might you go about generating a unique id for every document that is added to the site collection?

All the best Kieran

78lro
+1  A: 

So I am not sure I can really think of why you would actually need a "site collection unique" id, so maybe you can comment and let us know what is actually trying to be accomplished here...

Either way, all items have a UniqueID property that is a GUID if you really need it: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splistitem.uniqueid.aspx

spdevsolutions
A: 

Hi,

 We can get ID field in calculated column as below

Just copy past below formula into calculated field area

="ProductID"&[ID]

-Moorthy A

A: 

Hello,

The ="ProductID"&[ID] works expect when you try add a new task. It gives you a value of 0, but if you go back and re-create the column it will work. Does anyone know why this is?

A: 

Same conclusion ... "=SUM(1000,ID)" ID always worth 0 !! ID is not initialised apparently And I don't know why (is this a bug?)

A: 

Got the same pb !

I suppose that a bug, because when you create a new item, the ID is not yet define, so when SPS calculate the fields you got a blank instead of the ID... and will never apply it against you update the column definition in the field lists administration...

A: 

"The ="ProductID"&[ID] works expect when you try add a new task. It gives you a value of 0, but if you go back and re-create the column it will work. Does anyone know why this is?"

But why in the hell after re-creating the column it shows the correct data rather then just saving it again.

A: 

try to create a SPD workflow to papulate ID value into a another calculated filed(this field will have ID), and do cancatnation using calculated filed formula, it will give the how you want the unique value in sharepoint list

here using work flow , on item creation workflow will trigger and value will be dispalied in t your calculated filed

Peetha...

A: 

So I've added the ID field by modifying the views that I'm using - now is there a way to change the ID field to ID(link to item)? I thought there was a way to do this, but I'm not finding it in MOSS 2007. Thanks, Emby

Emby
I've created a new question as this one appears closed. http://stackoverflow.com/questions/607291/auto-number-column-in-sharepoint-list-with-link-to-item
Emby
A: 

Peetha has the best idea, I've done the same with a custom list in our SP site. Using a workflow to auto increment is the best way, and it is not that difficult. Check this website out: http://splittingshares.wordpress.com/2008/04/11/auto-increment-a-number-in-a-new-list-item/

I give much appreciation to the person who posted that solution, it is very cool!!

A: 

I know this thread is old, but I have a question: I can see the list ID column in my views if I so choose to see it; however, I can't see it when I view a list item or edit a list item. I don't see "ID" in the "Add from existing site columns" list of existing columns. Is there any way to get the ID to show on the screen during view/edit of a list item??

Mary
A: 

Sorry Mary, but you can't add it to the Editform.aspx or the displayform.aspx. But if you look up in the URL of the form, it is there:

yadayadayada/Editform.aspx?ID=23&yada yada yada

Of course, you will never see it on the Newform.aspx, as it has yet to be created!

Bill Garvey