2

How to resolve the following.

1.Created a custom list

2.Added one column with “Enforce unique values”

3.Added the item in list with value '111' for column created in step 2

4.Item is created in the list with ID=1

5.Tried creating another item and gave the value as '111' again for column created in step 2

6.Received the error "This value already exists in the list"

7.Changed the value to '222' and saved the item

8.Item is created in the list with ID=3

Item ID = 2 is skipped. Is there any setting to resolve this ?

1 Answer 1

0

In the content database there is a table “AllListsAux” with a column NextAvailableId. That value is incremented for the list before the validation has failed i.e. before the adding of the item has been cancelled.

There is no way to change that value except by running an SQL query but working with the database directly is not recommended. And also that would not be practical in your case because you will need to correct that value after every validation failure.

I am not sure how it will behave if you code the validation in ItemAdding event receiver instead of using ‘Enforce unique values’. If continues IDs is critical to you then you can try that but my guess is that it will have the same behaviour (problem).

4
  • Thank you Naim ! So I have to look for other option to get the proper incremental values in custom column to showcase that no records are deleted from list?
    – G Singh
    Commented Dec 10, 2013 at 12:58
  • Yes. I would not rely on IDs given by SharePoint. Commented Dec 10, 2013 at 13:30
  • Thank you Naim ! I will work on this. Please share if you know the best way to do this.
    – G Singh
    Commented Dec 11, 2013 at 4:41
  • One way to do it is by adding new column and in ItemAdding event receiver you set the value by first getting the last added item's value and incrementing it. For your case it also may be good to prevent users from deleting items. Instead add another Yes/No column for example called 'Active' or something. Commented Dec 11, 2013 at 7:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.