Skip to main content

Notifications

Power Apps - Building Power Apps
Answered

Remove From SharePoint If()

(0) ShareShare
ReportReport
Posted on by 212

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:
  • WarrenBelz Profile Picture
    WarrenBelz 145,526 on at
    Re: Remove From SharePoint If()

    @Hack-7 ,

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

  • cwebb365 Profile Picture
    cwebb365 3,294 on at
    Re: Remove From SharePoint If()

    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. 

  • Hack-7 Profile Picture
    Hack-7 212 on at
    Re: Remove From SharePoint If()

    @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?

  • Hack-7 Profile Picture
    Hack-7 212 on at
    Re: Remove From SharePoint If()

    @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
    Hack-7 212 on at
    Re: Remove From SharePoint If()

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

  • cwebb365 Profile Picture
    cwebb365 3,294 on at
    Re: Remove From SharePoint If()

    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. 

  • Mtthwlee88 Profile Picture
    Mtthwlee88 4 on at
    Re: Remove From SharePoint If()

    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/ 

  • Verified answer
    WarrenBelz Profile Picture
    WarrenBelz 145,526 on at
    Re: Remove From SharePoint If()

    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

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

Microsoft Kickstarter Events…

Register for Microsoft Kickstarter Events…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 145,526

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,907

Leaderboard