cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
PabloLopez
Frequent Visitor

Consecutive ID

Hello everyone.

 

I’m building an App for my company. I have the next situation.

 

My database is a Sharepoint List that has two columns called DESCRIPTION and ID. The column ID is from Sharepoint and is only required for count each record.

 

I have a Form for the people of my company fill up it. The field of this form is DESCRIPTION and my goal is when each person fill up this field, the app show the next ID (Last ID + 1) but when we want to edit some récord don’t create other ID.

 

Thanks for your support. 

2 ACCEPTED SOLUTIONS

Accepted Solutions

Hello @RandyHayes .

 

I understand you, but I was doing that (Update the DataSource) and the problem continue. See the next figure.

PabloLopez_0-1642083551175.png

The last figure is about my DataSource. I was removing some rows and then I updated my DataSource in Power Apps but the app doesn't recognize that change and shown all remove records.

 

Thank you for your support.

View solution in original post

Drrickryp
Super User
Super User

@PabloLopez 

Be aware that SharePoint Id's are not reused even if you delete them. Randy's formula will still give the next value as though the deleted rows were still there. This behavior is by design and makes sense. If Id's were reused once a record was deleted. The database would be corrupted.

View solution in original post

8 REPLIES 8
RandyHayes
Super User
Super User

@PabloLopez 

You can get the next ID with the following formula:

First(Sort(yourDataSource, Created, Descending)).ID

 

You haven't provided much detail on the form, or where the number goes, but from the above, you can get the last ID and then add 1 to it.

 

Keep in mind that doing this may not be accurate as, if you have multiple users of your app, another person can add a new record with a higher ID during the time that the first person does the same.  PowerApps will not recognize that someone else has added a record automatically.

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Hello @RandyHayes.

 

This is my Form.

PabloLopez_0-1641999437188.png

Actually the last number is 245 and I need that:  First record will be 246. The next one 247, etc.

I have a problem with your answer because the consecutive is above from my last number. When i fill up a test record, the visual element take into account the last test records, even though the data source does not contain this answers

PabloLopez_2-1642000385412.png

Relevant data:

Form name: Registro

Data Source: SDM, HK-5221

Last Record Number: 245

 

Thank you for your support.

hemrhk
Responsive Resident
Responsive Resident

@PabloLopez  Along with @RandyHayes  provided, before you save, filter the datasource with the ID you have calculated to see whether another user already created the record.

hemrhk
Responsive Resident
Responsive Resident

@PabloLopez  Along with @RandyHayes  provided, before you save, filter the datasource with the ID you have calculated to see whether another user already created the record.

@PabloLopez 

If that formula is showing you 259...then you have a 259 in your list!!  

If you have been deleting or changing records in the list while you have been working on the app, make sure you have refreshed the datasource in the designer.  It will not automatically update itself if you change anything in the list manually.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Hello @RandyHayes .

 

I understand you, but I was doing that (Update the DataSource) and the problem continue. See the next figure.

PabloLopez_0-1642083551175.png

The last figure is about my DataSource. I was removing some rows and then I updated my DataSource in Power Apps but the app doesn't recognize that change and shown all remove records.

 

Thank you for your support.

RandyHayes
Super User
Super User

@PabloLopez 

If you do a refresh on the datasource, then it should get the new values and exclude the ones removed.

 

From that photo, if you refresh your datasource, then the formula should be showing you 268.

What does it show?

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!
Drrickryp
Super User
Super User

@PabloLopez 

Be aware that SharePoint Id's are not reused even if you delete them. Randy's formula will still give the next value as though the deleted rows were still there. This behavior is by design and makes sense. If Id's were reused once a record was deleted. The database would be corrupted.

Helpful resources

Announcements
PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

Top Solution Authors
Top Kudoed Authors
Users online (1,214)