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 / Delete 3 items from 3 ...
Power Apps
Unanswered

Delete 3 items from 3 lists inside Power Apps canvas application will only remove 2 records

(0) ShareShare
ReportReport
Posted on by 1,807 Super User 2024 Season 1
I have 3 SharePoint lists, as follow:-
 
1) WorkOrders
2) WorkOrderInfoDetails
3) WorkOrderWorkOrderInfoDetails. storing the ID of the WorkOrders and the ID of the WorkOrderInfoDetails
 
and i have added a delete button, when clicked it will show a popup:-
 
 
 
the popup will show a component library which have "Enhanced component property" with this formula:-
 
 
here is the formula, which is suppose to delete the items from the above 3 lists:-
 
If(1=1,ClearCollect(
    varWOWOInfoDetails,
    Filter(
        'Work Orders Work Order Info Details',
        'Work Order ID' = DashBoardGallery_1.Selected.ID
    )
);
ClearCollect(
    varWOSP,
    Filter(
        'Work Orders Spare Parts',
        'Work Order ID' = DashBoardGallery_1.Selected.ID
    )
);
 
ForAll(varWOSP As wosp,
Collect(
    varWOSPWOSPAPP,
    Filter(
        'Work Order Spare Parts Work Order Spare Part Approvals',
        'Work Order Spare Part ID' = wosp.ID
    )
));
 
IfError(RemoveIf(
    'Work Orders',
        ID = DashBoardGallery_1.Selected.ID
),
Notify(
    "Can not delete work order",
    NotificationType.Error
),
ForAll(varWOWOInfoDetails As wowo,
RemoveIf('Work Orders Work Order Info Details',ID=wowo.ID);
RemoveIf('Work Orders Info Details',ID=wowo.'Work Order Info Detail ID')
 
);
ForAll(varWOWOInfoDetails As wowo,
 
RemoveIf('Work Orders Info Details',ID=wowo.'Work Order Info Detail ID');
RemoveIf('Work Orders Work Order Info Details',ID=wowo.ID);
);
 
 
but at the end the items will only get removed from the 2 lists "WorkOrders" & "WorkOrdersWorkOrdersInfoDetails", but will get skipped for the "WorkOrderInfoDetails" list, here is the recycle bin:-
 
 
i tried this on multiple items and all have the same issue, so what is wrong with my formula?
 
Categories:
I have the same question (0)
  • Suggested answer
    Artur Stepniak Profile Picture
    1,539 Super User 2025 Season 2 on at
    Hello,
     
    1. Why are you using a component instead of a standard button?
    2. Why the condition 1=1 is introduced? It's an unnecessary if. It'll always be true, so you're probably not reaching the code for Work Orders Info Details:
     
    ForAll(varWOWOInfoDetails As wowo,
    RemoveIf('Work Orders Work Order Info Details',ID=wowo.ID);
    RemoveIf('Work Orders Info Details',ID=wowo.'Work Order Info Detail ID')
     
    );
    ForAll(varWOWOInfoDetails As wowo,
     
    RemoveIf('Work Orders Info Details',ID=wowo.'Work Order Info Detail ID');
    RemoveIf('Work Orders Work Order Info Details',ID=wowo.ID);
    );
     
    I'd suggest you to optimize this code as it's really cluttered and hard to understand. Please comment it also for readability.
     
    In case of any other questions, let me know. If the answer helped you, mark it, so that others can benefit from it.
     
    Best regards,
     
    Artur Stepniak
  • johnjohnPter Profile Picture
    1,807 Super User 2024 Season 1 on at
     
    1) I am using component to build a reusable popup on multiple screens. hope this make sense to you
     
    2) the condition 1=1 was used during my debug, it should not affect the flow, am i correcT?
     
     
     
    also i am doing those actions twice, because of the weired outcome i got on that some items did not get deleted..:-
     
    ForAll(varWOWOInfoDetails As wowo,

    RemoveIf('Work Orders Work Order Info Details',ID=wowo.ID);

    RemoveIf('Work Orders Info Details',ID=wowo.'Work Order Info Detail ID')

     
     
    );

    ForAll(varWOWOInfoDetails As wowo,

     
     
    RemoveIf('Work Orders Info Details',ID=wowo.'Work Order Info Detail ID');

    RemoveIf('Work Orders Work Order Info Details',ID=wowo.ID);

    );
     
     
     
     
  • Suggested answer
    Artur Stepniak Profile Picture
    1,539 Super User 2025 Season 2 on at
    Hello,
     
    1. Yes, it makes sense. :-)
    2. It could affect the flow, because the condition is always true, which means that it'll only run the code in the if statement which's evaluated to true. Probably that's why you're encountering a weird behaviour.
     
    Please also delete the repeated remove actions as it'll generate more errors.
     
    In case of any other questions, let me know. If the answer helped you, mark it, so that others can benefit from it.
     
    Best regards,
     
    Artur Stepniak
  • johnjohnPter Profile Picture
    1,807 Super User 2024 Season 1 on at
     
    I am not sure why you are concentrating on the 1=1,,, i always want to perform the actions inside the If statement true condition, and i added this condition because i were facing issues with deleting the 3 items .. also the repeated delete actions  will not harm, it can give an indication where the problem is , that why i keep it...
  • Suggested answer
    Artur Stepniak Profile Picture
    1,539 Super User 2025 Season 2 on at
    Hello,
     
    no problem if you'd like to have it like that. I'm just telling you that it clutters the code and probably this if is the root cause, because you have some code here after the comma. It'll run only if the if condition is false, which will never occur:
     
    ),
    Notify(
        "Can not delete work order",
        NotificationType.Error
    ),
    ForAll(varWOWOInfoDetails As wowo,
    RemoveIf('Work Orders Work Order Info Details',ID=wowo.ID);
    RemoveIf('Work Orders Info Details',ID=wowo.'Work Order Info Detail ID')
     
    );
    ForAll(varWOWOInfoDetails As wowo,
     
    RemoveIf('Work Orders Info Details',ID=wowo.'Work Order Info Detail ID');
    RemoveIf('Work Orders Work Order Info Details',ID=wowo.ID);
     
     
    Instead of repeating actions, it's better to comment that there's an issue. Nevertheless, repeating actions won't make it work.
    I also see that you're missing some brackets, see in VSCode:
     
     
     
    In case of any other questions, let me know. If the answer helped you, mark it, so that others can benefit from it.
     
    Best regards,
     
    Artur Stepniak
  • johnjohnPter Profile Picture
    1,807 Super User 2024 Season 1 on at
     
    Thanks for your help, but be sure it is not about the condition, here is my full code. you can see that all the conditions will always run, as follow:-
     
    If(1=1,ClearCollect(
        varWOWOInfoDetails,
        Filter(
            'Work Orders Work Order Info Details',
            'Work Order ID' = DashBoardGallery_1.Selected.ID
        )
    );
    ClearCollect(
        varWOSP,
        Filter(
            'Work Orders Spare Parts',
            'Work Order ID' = DashBoardGallery_1.Selected.ID
        )
    );
    ForAll(varWOSP As wosp,
    Collect(
        varWOSPWOSPAPP,
        Filter(
            'Work Order Spare Parts Work Order Spare Part Approvals',
            'Work Order Spare Part ID' = wosp.ID
        )
    ));
    IfError(RemoveIf(
        'Work Orders',
            ID = DashBoardGallery_1.Selected.ID
    ),
    Notify(
        "Can not delete work order",
        NotificationType.Error
    ),
    ForAll(varWOWOInfoDetails As wowo,
    RemoveIf('Work Orders Work Order Info Details',ID=wowo.ID);
    RemoveIf('Work Orders Info Details',ID=wowo.'Work Order Info Detail ID')
    );
    ForAll(varWOWOInfoDetails As wowo,
    RemoveIf('Work Orders Info Details',ID=wowo.'Work Order Info Detail ID');
    RemoveIf('Work Orders Work Order Info Details',ID=wowo.ID);
    );
    ForAll(varWOSP As wosp,
    RemoveIf('Work Orders Spare Part Details','Work Order Spare Part ID'=wosp.ID)
    );
    ForAll(varWOSPWOSPAPP As wospwoapp,
    RemoveIf('Work Orders Spare Part Approvals',ID=wospwoapp.'Work Order Spare Part Approval ID');
    );
    ForAll(varWOSPWOSPAPP As wospwoapp,
    RemoveIf('Work Order Spare Parts Work Order Spare Part Approvals',ID=wospwoapp.ID);
    );
    ForAll(varWOSP As wosp,
    RemoveIf('Work Orders Spare Parts',ID=wosp.ID);
    );Notify(
        "Deleted successfully",
        NotificationType.Success
    ););

    UpdateContext({showPopup: false});
    Set(selectedID,DashBoardGallery_1.Selected.ID);
    Set(
        selectedID,
        Blank()
    );
    Set(
        varPrintProcessID,
        Blank()
    );
    Set(
        varPrintProcessPrintOrder,
        Blank()
    );
    Set(
        varPostingUnPotingProcess,
        Blank()
    );
    Set(
        varPostingUnPotingProcessPostingUnPostingForms,
        Blank()
    ),"");


    Also if i use this formula -without the IF-, i will get the exact issue:-

    ClearCollect(
        varWOWOInfoDetails,
        Filter(
            'Work Orders Work Order Info Details',
            'Work Order ID' = DashBoardGallery_1.Selected.ID
        )
    );
    ClearCollect(
        varWOSP,
        Filter(
            'Work Orders Spare Parts',
            'Work Order ID' = DashBoardGallery_1.Selected.ID
        )
    );
    ForAll(varWOSP As wosp,
    Collect(
        varWOSPWOSPAPP,
        Filter(
            'Work Order Spare Parts Work Order Spare Part Approvals',
            'Work Order Spare Part ID' = wosp.ID
        )
    ));
    IfError(RemoveIf(
        'Work Orders',
            ID = DashBoardGallery_1.Selected.ID
    ),
    Notify(
        "Can not delete work order",
        NotificationType.Error
    ),
    ForAll(varWOWOInfoDetails As wowo,
    RemoveIf('Work Orders Work Order Info Details',ID=wowo.ID);
    RemoveIf('Work Orders Info Details',ID=wowo.'Work Order Info Detail ID')
    );
    ForAll(varWOWOInfoDetails As wowo,
    RemoveIf('Work Orders Info Details',ID=wowo.'Work Order Info Detail ID');
    RemoveIf('Work Orders Work Order Info Details',ID=wowo.ID);
    );
    ForAll(varWOSP As wosp,
    RemoveIf('Work Orders Spare Part Details','Work Order Spare Part ID'=wosp.ID)
    );
    ForAll(varWOSPWOSPAPP As wospwoapp,
    RemoveIf('Work Orders Spare Part Approvals',ID=wospwoapp.'Work Order Spare Part Approval ID');
    );
    ForAll(varWOSPWOSPAPP As wospwoapp,
    RemoveIf('Work Order Spare Parts Work Order Spare Part Approvals',ID=wospwoapp.ID);
    );
    ForAll(varWOSP As wosp,
    RemoveIf('Work Orders Spare Parts',ID=wosp.ID);
    );Notify(
        "Deleted successfully",
        NotificationType.Success
    ););

    UpdateContext({showPopup: false});
    Set(selectedID,DashBoardGallery_1.Selected.ID);
    Set(
        selectedID,
        Blank()
    );
    Set(
        varPrintProcessID,
        Blank()
    );
    Set(
        varPrintProcessPrintOrder,
        Blank()
    );
    Set(
        varPostingUnPotingProcess,
        Blank()
    );
    Set(
        varPostingUnPotingProcessPostingUnPostingForms,
        Blank()
    );

  • Suggested answer
    Artur Stepniak Profile Picture
    1,539 Super User 2025 Season 2 on at
    Hello,
     
    it looks better! Something is still wrong with those RemoveIf() statements, you're using nested ifs and probably it's just gets totally messed up. Why not using just Remove() and using a LookUp? You could also, before starting this logic, set variables for each record, instead of querying them from RemoveIf(). It'll get cleaner.
     
    In case of any other questions, let me know. If the answer helped you, mark it, so that others can benefit from it.
     
    Best regards,
     
    Artur Stepniak

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 840 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 332 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 275

Last 30 days Overall leaderboard