Hi,
In MOSS 2007, we do not have any option to set unique column value for the field in document library or list. We can still achieve that with the help of event handlers and adding some code in the ItemAdding event. But still there was no direct way to do it.
Now in SharePoint 2010, we have the built in functionality to enforce the uniqueness of the field. But yes do remember that the field must be indexed first before you want to set it as a primary key.
Well, just a quick question. Do we have anything as primary key in MOSS 2007? Yes, we do have and that is ID field in list or library. However that does not solve the purpose as it is just used to identify items and used heavily in coding purpose.
So let’s see how to go ahead with primary key in list field.
Create a list in SharePoint 2010 site and then create a field that you want to have a primary key. Go to list settings. Go to indexed columns and choose that column to be indexed.
You can index up to 20 fields per list as you can see in the screen shot. I have already created one index which is on EmployeeID field in the list.
When you create a field now then we have an option to enforce the unique value. This can be set only when you have made that column indexed. So if you have not indexed this column, SP 2010 will ask you to do it.
Once you set this field as unique key, then go ahead and add one value and try to add another with the same. It will not allow you to do so and show the message.
Unique field is case insensitive. So if you have Microsoft and MICROSOFT, it means same to the field. It is unique.it won’t allow you to save.
Same is enforced even when you update the item.
Supported Column Types
• Single line of text
• Choice field (but not multichoice)
• Number
• Currency
• Date/ Time
• Lookup (but not multivalve)
• Person or Group (but not multivalve)
• Title (but not in a document library)
Do remember that When you enforce uniqueness on a Lookup column, the list item in the target list can have only one list item looking up to it from the child list.
SharePoint Kings,Technosavvy guys hunting SharePoint Challenges... SharePoint 2013, SharePoint 2010, MOSS 2007, Windows Workflow Foundation, Project Server and Other Related Technologies.
Subscribe to:
Post Comments (Atom)
Share your SharePoint Experiences with us...
As good as the SharePointKings is, we want to make it even better. One of our most valuable sources of input for our Blog Posts comes from ever enthusiastic Visitors/Readers. We welcome every Visitor/Reader to contribute their experiences with SharePoint. It may be in the form of a code stub, snippet, any tips and trick or any crazy thing you have tried with SharePoint.
Send your Articles to sharepointkings@gmail.com with your Profile Summary. We will Post them. The idea is to act as a bridge between you Readers!!!
If anyone would like to have their advertisement posted on this blog, please send us the requirement details to sharepointkings@gmail.com
No comments:
Post a Comment