Solved

Reseting Primary Key / ID on Sharepoint 2013 list

Posted on 2015-02-13
4
880 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 34

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

We are happy to announce a brand new addition to our line of acclaimed email signature management products – CodeTwo Email Signatures for Office 365.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

867 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now