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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Remove From SharePoint...
Power Apps
Answered

Remove From SharePoint If()

(0) ShareShare
ReportReport
Posted on by 226 Moderator

I have been looking at this for a while and I am once again stumped!  Any suggestions would be great.

 

My App, loads a collection of Users and displays them in a gallery.  If the user presses a minus button it removes the entry in the gallery.  At this point, it does not Patch() the SP list.  It just removes the entry from the collection and gallery.

 

The user can also search and 'Add' new names to the collection which shows all details in the gallery.  Again, nothing is Patched to SP list at this point.

 

When all adding and removing is done, I need to Patch() the details back to SP.  But, I cannot figure out the logic of remove() or patch(defaults()). 

 

So I was thinking about deleting all records in the collection from the SP list and then doing a ForAll(Patch(()), but the logic of removeif() is messing with me.    I am sure I am not looking at this properly.

 

ForAll(
 collectionName,
 RemoveIf(
 spListName,
 [@collectionName].teamID = ID
 )
);

 

Any thoughts?

 

 

 

 

Categories:
I have the same question (0)
  • Verified answer
    WarrenBelz Profile Picture
    155,224 Most Valuable Professional on at

    Hi @Hack-7 ,

    You have already done the removing, but the conundrum is how do your remove something from the list that is no longer in the collection ? If this is what you are trying to do, then you need to flag the collection item for removal (you can use AddColumns on the Collection at the start) and flag the items as N (New) or R (Remove) then two actions

    ForAll(
     Filter(
     collectionName,
     Flag = "R"
     ) As _Items,
     RemoveIf(
     spListName,
     ID = _Items.teamID
     )
    )

    Then the new ones

    Patch(
     spListName,
     ForAll(
     Filter(
     collectionName,
     flag = "N"
     ) As _Items,
     {
     field1: _Items.field1,
     field2: _Items.field2,
     field3: . . . . 
     }
     )
    )

    Note that there may be a quicker way if all of the columns in your collection are present in the List in both field name and type

    Patch(
     spListName,
     Filter(
     collectionName,
     flag = "N"
     )
    ) 

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    MVP (Business Applications)   Visit my blog Practical Power Apps

  • Mtthwlee88 Profile Picture
    4 on at

    I would not suggest deleting all records from the SharePoint list only to patch them back to the SharePoint list. That's a lot of data and could really slow down your app. 

     

    I learned a trick from Matthew Devaney using toggles to detect what was updated or changed and only updating those records. Here is a link to the article and you could start on the section 'Detecting Edited Rows':
    https://www.matthewdevaney.com/power-apps-excel-style-editable-table-part-1/ 

  • cwebb365 Profile Picture
    3,294 Most Valuable Professional on at

    If you are pulling the SharePoint items straight into the collection as is. Then you can just use Patch(collection); and let powerapps handle doing edits and new ones. Works great. 

     

    Then for deletion. I just keep a colRemoveItems and add anything that gets removed gets added to that collection, then you can call the removeif or for all and remove in it from the items in remove collection. 

     

    Assuming you need this, otherwise ditch the collection and work straight in the datasource. But I'm guessing your designing around a "Save" button to commit changes. 

  • Hack-7 Profile Picture
    226 Moderator on at

    @Mtthwlee88 Thanks for the note.  I will go review the article today.  Cheers

  • Hack-7 Profile Picture
    226 Moderator on at

    @cwebb365 Thanks for the suggestions, question for you.  Patch(collection) does that handle both adding new items to the list as well as modifying existing ones?

    The reason I went towards a collection was for the reason that we want the user to build a 'team' list before committing the changes back to the SharePoint list.

    Hence the reason why I thought removing all items from SP based on filters and then Patching all current collection items back.

  • Hack-7 Profile Picture
    226 Moderator on at

    @WarrenBelz my thought process (and it could be all wrong) was to remove all items in the collection from the SP list, then do a  ForAll(Patch(()) for the items in the list.

    Is my theory on this the wrong way to proceed?

  • cwebb365 Profile Picture
    3,294 Most Valuable Professional on at

    Yes, if you pull the whole records from the SharePoint list to build you're collection, you can simply call Patch(collection) and it will handle adding and editing items from the collection assuming "Required" fields are filled into the collection. Obviously ID will be blank and that lets it know to create a new one. 

     

    So usuaully I would use Patch(Collection) then have a collectionItemstodelete where I just collect the item I'm deleting before removing it form the collection. Then when I save I do a forall(collectionitemstodelete), Remove('list', ID = ThisRecord.ID))  

     

    Syntax might not be exact but that's how I handle this. 

  • WarrenBelz Profile Picture
    155,224 Most Valuable Professional on at

    @Hack-7 ,

    That would work also but is an extra step to simply filtering the collection for the new items.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Vish WR Profile Picture

Vish WR 762

#2
11manish Profile Picture

11manish 640

#3
Valantis Profile Picture

Valantis 548

Last 30 days Overall leaderboard