Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Reseting Primary Key / ID on Sharepoint 2013 list

Posted on 2015-02-13
4
Medium Priority
?
1,522 Views
Last Modified: 2015-02-13
Hello - I need to know how to use a resetting key or field on a SharePoint list (that is accessed by Access 2013 as a table). Currently, the primary key (ID) does not reset to 0 when all records in the table are deleted. When it was an Access table, it would reset to 0, and a query would populate the table in a way that the ID would populate 1, 2, 3, 4.... Now while using the SharePoint list, the ID retains the last value and doesn't reset. The problem is that I have follow on queries that rely on this ID value starting at 0 each time. Since it doesn't reset the queries aren't running properly.

So again in summary, I just need an autonumber SharePoint list field to reset each time the table is completely deleted to 0 records, or a workaround using a ID that starts at 1 each time the table is loaded with new records (and no previous records).

Thanks,

Mike
0
Comment
Question by:maknit
  • 2
4 Comments
 
LVL 85
ID: 40608235
When it was an Access table, i
Access does not do that unless you Compacted the database after the delete. I would assume you'd have to "compact" the Sharepoint list as well, or re-output the table to Sharepoint.

A bigger problem is that you're depending on an AutoNumber field to be sequential, and there is no guarantee of that. It's guaranteed to be unique, of course, but not sequential. You would be much better of redesigning your system to use a different ordering method. If you load your records in a specific manner, then the same method you use for that "specific manner" could be used to order the records afterwards. For example, if you load records sequentially based on a Date field, you could then make sure your queries and such use that same Date field to Order By when you're viewing them in a Form or Report, or when you're working with them in a Query.
0
 

Author Comment

by:maknit
ID: 40608271
Ok - thanks - I was thinking that would be a limitation of the SP Lists. The autonumber worked in the past because the query that loaded the table would sequentially load a fixed amount of date sorted records - worked every time because of this, and I believe another outcome wasn't even really possible as long as the date sorting of loaded data never changed. So the row num always matched the right record (actually a period number - think 1 - 12, a rolling 12 month set of monthly periods where period 1 is always the current month, and period 12 would be a year out from period 1).  It sounds like I'll need to basically manually set an id or sequence field to do the same thing the autonumber used to do, before the query runs. Not as simple as the current method, but probably doable. Thanks.
0
 
LVL 40

Accepted Solution

by:
PatHartman earned 2000 total points
ID: 40608527
If the current month is always period 1, then you can calculate the value of the other periods based on their relationship to the current month.  The DateDiff() function using "m" as the unit should give you the period.
0
 

Author Comment

by:maknit
ID: 40608540
Thanks - that's a great idea.

It didn't let me select both solutions - but note that both comments from Scott McDaniel and PatHartman collectively make the solution.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post, I will showcase the steps for how to create groups in Office 365. Office 365 groups allow for ease of flexibility and collaboration between staff members.
In a use case, a user needs to close an opened report by simply pressing the Escape (Esc) key. This can be done by adding macro code in Report_KeyPress or Report_KeyDown event.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question