Solved

Reseting Primary Key / ID on Sharepoint 2013 list

Posted on 2015-02-13
4
953 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 84
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 35

Accepted Solution

by:
PatHartman earned 500 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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
FrontEnd tools to create web database application 7 61
User Level Security 6 38
Office 365 Group Distribution Lists 5 26
Access Delete Query Not Working 13 32
Cloud-based technologies and services will continue to grow in popularity in 2017 thanks to the simple, scalable and cost-effective solutions they deliver. Here are three areas where cloud adoption is poised to really take off.
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

809 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