web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Function deleting all ...
Power Apps
Suggested Answer

Function deleting all records in a table when it was not supposed to. HELP!!!

(1) ShareShare
ReportReport
Posted on by 6
 
Hello, I'm new to Power Apps and created a simple delete function in the OnSelect property of a button to remove records from a SharePoint list. However, when I click the button, it removes all records instead of only those specified and filtered. I have reviewed my code multiple times and tried adjusting the filters, but I haven't been able to resolve the issue.
 
Here is the code I am using (I translated it for the English version of Power Apps, as I use the French version. Some syntax may be different; sorry if anything is incorrect):
 
ForAll(
    Filter(ColfilteredInProgress; ischoosen),
    Switch(
        ThisRecord.n_task,
        "1.01.002",
            RemoveIf(
                tb_en_1_002,
                n_rg = ThisRecord.n_rg && n_task = ThisRecord.n_task
            ),
        "1.01.006",
            RemoveIf(
                tb_en_1_006,
                n_rg = ThisRecord.n_rg && n_task = ThisRecord.n_task
            ),
        "1.01.011",
            RemoveIf(
                tb_en_1_011,
                n_rg = ThisRecord.n_rg && n_task = ThisRecord.n_task
            ),
        Notify(
            "Error: Task Number " & ThisRecord.n_task & " does not correspond to any registered table.",
            NotificationType.Error
        )
    )
);

To provide some additional context:
  • ColfilteredInProgress is a collection derived from the main SharePoint list and is displayed in a gallery. Users can select items in the gallery, and the button with the delete function is enabled based on this selection. The ischoosen parameter indicates whether any item in the gallery is selected or not, with checkboxes used for selection.
  • I have a main SharePoint list that manages "service orders". Each line in this list has a unique combination of n_rg and n_task. For example, n_rg: 12 and n_task: 1.01.002 is unique and cannot be repeated for the same service order.
  • Each service order can have multiple tasks, and each task has a specific n_task value that like I said does not repeat for the same service order or n_rg.
  • There are lists that receive one or more specific n_task values. Each individual list was created to store data entered by the user for a specific task. These lists inherit the n_rg and n_task values when records are added to the list.

 

Could you help me understand why all records are being removed and how to fix it, even though I have specified and filtered which ones should be deleted?

I've encountered a solution, but it's not very clean. It involves the following steps:

ClearCollect(
colToRemove1_002,
Filter(
tb_en_1_002,
n_rg in Filter(ColfilteredInProgress; ischoosen).n_rg &&
n_task in Filter(ColfilteredInProgress; ischoosen).n_task
)
);
ForAll(
colToRemove1_002,
Remove(tb_en_1_002, ThisRecord)
);

This process would need to be repeated for each n_task, which can be cumbersome as there are many tasks to consider. Additionally, there are delegation issues that need to be addressed with this approach.

Categories:
I have the same question (0)
  • Suggested answer
    Michael E. Gernaey Profile Picture
    53,493 Super User 2025 Season 2 on at
    So weird... I posted an answer for you but its gone, like a long answer ugg.
     
    I believe you are unintentionally triggering the delete every time.
     
    Please change your code to 
    Filter(ColfilteredInProgress; ischoosen = true)
     
    Also, you can add a Trace Statement right after the filter, and you can write out the value of ischoosen, and if you say have 40 records and you get ischoosen (you original code) 40 times true,
     
    then change the code to what I suggested and see if it fixes it.
     
  • CU31071336-0 Profile Picture
    6 on at
     
    Thank you for answering my question. I tried the solution you proposed before and tested it a couple
    more times to be sure. Based on the results from the `Trace` function
    (which I didn't know existed—thank you for guiding me on that), I confirmed that the
    `ischoosen` property correctly reflects the number of selected items. 
    However, it still keeps deleting records it shouldn't.

    For example, I have two records in the SharePoint list `tb_en_1_002`:

    1. First record: `n_rg = 12`, `n_task = 1.02.002`
    2. Second record: `n_rg = 155`, `n_task = 1.02.002`

    The code successfully deletes both records from the SharePoint list, but it shouldn't.

    The filter is accurately picking the exact line I selected in the main gallery,
    which only has one `n_rg` (12) and one `n_task` (1.02.002).

    Oh and here's how I used the Trace function:
    ForAll(
        Filter(ColfilteredInProgress, ischoosen = true),
        Trace("Processing Record: n_rg = " & ThisRecord.n_rg & "; n_ensaio = " & ThisRecord.n_ensaio & ";
    ischoosen = " & ThisRecord.ischoosen)

    The rest of the code remains the same as the one I sent before.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 765 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 272

Last 30 days Overall leaderboard