Solved

Reseting Primary Key / ID on Sharepoint 2013 list

Posted on 2015-02-13
4
802 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

763 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

9 Experts available now in Live!

Get 1:1 Help Now