none
start List item id from 500 instead from 20

    Question

  • hi ,

    i have a list in which i have 20 items,i have got the requirement that new list items id should start from 500,instead from 21

    i have used below code to add new item  to list  and update listitemid with 500 it worked fine,but when i try to add new item from the UI(List/newitem) the ID value is 21 not 501

       Please letme know is their any way to start list item id from specific number .                                                             

    code which i am using to update list item id           

                                 web.AllowUnsafeUpdates = true;
                        site.AllowUnsafeUpdates = true;
                       SPList list = web.Lists.TryGetList("test");
                       list.Fields[SPBuiltInFieldId.ID].ReadOnlyField = false;        
                       list.Fields[SPBuiltInFieldId.ID].Update();
                         list.Update();                    
                       SPListItem item = list.AddItem();
                       item["Title"] = "This item Id's is not auto-generated by SharePoint, it is explicitly specified";
                    item[SPBuiltInFieldId.ID] = 500;
                     item.Update();                                 
                     list.Fields[SPBuiltInFieldId.ID].ReadOnlyField = true;
                       list.Update();
          

    Note:

    i cant use event receivers to set list item id on ItemAdded or itemadding

    i cant update in Database



    • Edited by suchithraj Tuesday, July 23, 2013 1:24 PM
    Tuesday, July 23, 2013 1:09 PM

All replies

  • I don't think this is possible without event receivers. As a workaround, you can try creating a calculated field with the formula as 500+ID or use SPD workflow.

    --Cheers


    • Edited by Prasath C Tuesday, July 23, 2013 1:25 PM more info
    Tuesday, July 23, 2013 1:24 PM
  • When I've encountered this requirement in the past, the common solution has been to run a script to create and delete items until the ID has incremented to the desired number. That said, you might be better off using a different field than SharePoint's item ID field, since it can't be displayed in out-of-the-box forms and alerts. You could use a calculated column as Prasath C suggested, or use a SharePoint Designer workflow to copy the ID (plus x) to a normal text or number field whenever items are added/updated.
    Tuesday, July 23, 2013 3:09 PM
  • thank you for the suggestion,but unfortunately i can use calculated field .i need to use list id field only
    Thursday, July 25, 2013 12:59 PM
  • thanks for the suggestion.
    Thursday, July 25, 2013 1:01 PM