Link to home
Start Free TrialLog in
Avatar of piattnd
piattnd

asked on

Sharepoint Knowledgebase: How to automatically generate and assign a document ID?

Experts:

I'm setting up a knowledge base within Sharepoint Services using the Knowledge Base plugin provided by Microsoft.  I've got the website up and running and I know how to add customized columns when documents are being created.

What I want to tackle now is a unique ID for the document.  When a user creates a document, I want a field called Document ID to auto generate a document ID for the document.  This ID is unique to the document and will never be used again.

Any ideas on how I can do that?
Avatar of zephyr_hex (Megan)
zephyr_hex (Megan)
Flag of United States of America image

if it's just one library, you can use the built in ID field.  it's hidden by default.
http://geekswithblogs.net/hinshelm/archive/2008/01/11/unique-id-in-sharepoint-list.aspx

if you need something that is global (covers more than one library), or this built in ID field doesn't suit your requirements, then you'll need to build a customization.  in my opinion, the easiest way to do this is using SQL.  you'd create a table that calculates and stores your ID.  maybe even using an Identity column.  SQL will enforce the uniqueness requirement, and handle the calculation of the next ID.  you'd then need to associate this to your library... and there are various ways in which to do that.   but try the built-in ID column first.
Avatar of piattnd
piattnd

ASKER

So is there a way to force this field to be readable (read only) upon creation of the document?  I want the users to create a new document and name the folders to contain the images specifically to the ID of the document.
Avatar of piattnd

ASKER

I meant during the creation of the document, sorry for the mis-wording there.
that built-in ID is read-only.  the user can not change it.  sharepoint assigns it, and it is unique.  there are situations in which this ID just doesn't work.  one situation is if you need it to be unique across multiple libraries.  that built-in ID is only unique within that library.

another example of some trouble with that ID is when you need the ID before the item is created.  the ID is assigned as part of the item creation, and so it's not available beforehand.  

so, if the document is added first, then you can use that ID to name the folder.  but you can't name the folder before the doc is created.  there are ways around this particular issue, or... you can use a different method for assigning the ID.  SQL is one way, and i've seen other solutions, too.
one more thing...
i am pretty sure that the ID does not get re-cycled if an item is deleted.  you can test it to check.  add the ID to the display of your library.  create an item, note the ID, and then delete the item.  then add another item.  i am pretty sure sharepoint will not re-use that deleted item's ID.

for some people, this is a problem because they want more of an "incrementer" than a unique ID... something that doesn't have gaps.  but as i recall, that ID field is indeed unique to the docs in the library.
Avatar of piattnd

ASKER

Yeah, the thing I just thought about too is what happens if I had to restore my site from a disaster.  Would that ID be reset?  I would think not, but I'm not too sure.

Do you have any links for the custom solution using an SQL table to calculate the next available ID?
SOLUTION
Avatar of sharepointguru14
sharepointguru14

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of piattnd

ASKER

We are not using sharepoint 2010, but I did see where it has a unique ID feature.  I don't know if we'll upgrade that way or not.

For now, I've gone ahead with manually assigning unique IDs to the documents.  Thank you both for your time and suggestions.

I'll look into the SQL IDENTITY link.