Skip to main content

Notifications

Power Apps - Building Power Apps
Suggested answer

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

Posted on 2 Dec 2024 22:18:27 by 1,354
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?
 
  • Suggested answer
    Artur Stepniak Profile Picture
    Artur Stepniak 296 on 04 Dec 2024 at 08:50:37
    Delete 3 items from 3 lists inside Power Apps canvas application will only remove 2 records
    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
    johnjohnPter 1,354 on 03 Dec 2024 at 18:48:07
    Delete 3 items from 3 lists inside Power Apps canvas application will only remove 2 records
     
    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
    Artur Stepniak 296 on 03 Dec 2024 at 08:59:13
    Delete 3 items from 3 lists inside Power Apps canvas application will only remove 2 records
    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

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

November 2024 Newsletter…

November 2024 Community Newsletter…

Community Update Oct 28…

Power Platform Community Update…

Tuesday Tip #7 Community Profile Tips…

Welcome to a brand new series, Tuesday Tips…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 143,372

#2
RandyHayes Profile Picture

RandyHayes 76,308

#3
Pstork1 Profile Picture

Pstork1 63,900

Leaderboard