cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
AdamH
Helper V
Helper V

Delete button removing top record rather than selected record

Hi All,

 

I've noticed a problem when deleting records within my app. As an example, I have 9 records, 1 to 9. If I select record 4 and select the delete button from the details screen, the app will delete record 1. If I select record 5 and select delete from the details screen, the app will delete record 2 and so on. 

 

From the detailscreen, I have my 'trash can' which navigates to a (deletewarning) screen using .Navigate(DeleteWarning)

From the DeleteWarning screen, my delete button uses .OnSelect - Remove([@'NC Codes'], BrowseGallery1.Selected); If (IsEmpty(Errors([@'NC Codes'], BrowseGallery1.Selected)), Navigate(AdminBrowseScreen1))

 

What could be happening here?

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User III
Super User III

@AdamH 

For some reason your Gallery is getting refreshed and reset to the first row.

If you have something in your app that would cause it, then you cannot rely on the .Selected of the gallery.  IN this case, you should consider a snapshot variable from your Gallery.

So, in the OnSelect of the Gallery, or in some button or icon OnSelect that you might be using to navigate to the details screen, add this formula:  Set(glbCurrentRecord, ThisItem)

Then for your Remove formula, change to the following:

RemoveIf([@'NC Codes'], ID=glbCurrentRecord.ID);

This assumes that ID is the primary key of your list (i.e. SharePoint), if not, replace with the primary key of your list.

 

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.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

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

View solution in original post

4 REPLIES 4
CNT
Community Champion
Community Champion

@AdamH  Does it work in the same screen where the Gallery is without navigating to another screen?

RandyHayes
Super User III
Super User III

@AdamH 

For some reason your Gallery is getting refreshed and reset to the first row.

If you have something in your app that would cause it, then you cannot rely on the .Selected of the gallery.  IN this case, you should consider a snapshot variable from your Gallery.

So, in the OnSelect of the Gallery, or in some button or icon OnSelect that you might be using to navigate to the details screen, add this formula:  Set(glbCurrentRecord, ThisItem)

Then for your Remove formula, change to the following:

RemoveIf([@'NC Codes'], ID=glbCurrentRecord.ID);

This assumes that ID is the primary key of your list (i.e. SharePoint), if not, replace with the primary key of your list.

 

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.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

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

View solution in original post

AdamH
Helper V
Helper V

@CNT 

It did the same if I add the code to the original detail screen. 

 

@RandyHayes 

I tried your solution and it worked and deleted the record I had selected, I just added the ; Navigate part, which I guess you left to prompt me to add where I wanted to go after the record was deleted. 

RemoveIf([@'NC Codes'], ID=glbCurrentRecord.ID); Navigate(adminbrowsescreen)

 

Thanks for the help again guys! 

RandyHayes
Super User III
Super User III

@AdamH 

Excellent!  Glad it is working.  

Yes, I had specifically said just "change your Remove formula" - meaning just that remove that you had...was lazy and didn't type the rest 😁

_____________________________________________________________________________________
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.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

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

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.

Users online (1,493)