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 / Clear Collection once ...
Power Apps
Unanswered

Clear Collection once Patch successful

(0) ShareShare
ReportReport
Posted on by 6

Hi,

I am fairly new to powerapps and am trying to build an App which holds records in a local collection, patches them to a SharePoint list then clears the list once the Patch has been executed successfully. I am happy with the Patch syntax however I cant work out how to initiate any follow up behavior once the patch has been successful, ie clear collection, post error message etc.

I have pasted my Patch below wich is currently triggered by pressing a button although I aim to build this into the workflow later once I understand the syntax required for this: ('LocalVisits' is the collection and 'PPM Visit Records' is the Sharepoint list with matching fields)

ForAll(

    LocalVisits,

    Patch(

        'PPM Visit Records',

        Defaults('PPM Visit Records'),

        {

            Title: Title,

            Start_Time: Start_Time,

            Visit_Region: Visit_Region,

            Visit_Location: Visit_Location,

            Team_Size: Team_Size,

            Activity: Activity,

            Comments: Comments,

            Latitude: Latitude,

            Longitude: Longitude

        }

    )

)

 

Any assistance would be greatly appreciated.

Categories:
I have the same question (0)
  • pontusofsweden Profile Picture
    255 on at

    Hi!

     

    To clear the collection after the patch operation, just add the Clear function after Patch. See my addition below in red:

     

    ForAll(

    LocalVisits,

    Patch(

    'PPM Visit Records',

    Defaults('PPM Visit Records'),

    {

    Title: Title,

    Start_Time: Start_Time,

    Visit_Region: Visit_Region,

    Visit_Location: Visit_Location,

    Team_Size: Team_Size,

    Activity: Activity,

    Comments: Comments,

    Latitude: Latitude,

    Longitude: Longitude

    }

    )

    ;Clear(LocalVisits)

     

    BR

    Pontus

  • AndyDickson Profile Picture
    6 on at

    Many thanks for the response.

     

    Will this only clear the collection if the patch is successful or will it clear it regardless? My concern is that if for some reason the patch is not successful the records will be lost with no warning.

     

    Thanks

    Andy 

  • pontusofsweden Profile Picture
    255 on at

    Hi,

     

    No this removes the records regardless.

     

    However, since the Patch function returns the patched record, you could use a Collect function (new collection) to fetch the successful records and the use it to remove recors from LocalVisits. So, it´s a 2 step rocket:

     

    1. 

    ForAll(

    LocalVisits,

    Collect(RemoveRecords,

    Patch(

    'PPM Visit Records',

    Defaults('PPM Visit Records'),

    {

    Title: Title,

    Start_Time: Start_Time,

    Visit_Region: Visit_Region,

    Visit_Location: Visit_Location,

    Team_Size: Team_Size,

    Activity: Activity,

    Comments: Comments,

    Latitude: Latitude,

    Longitude: Longitude

    }

    )

    )

    )

     

    2. Remove if success. Dont know what the unique identifier is here. Lets pretend that Title is unique:

    Remove(LocalVisits, Filter(LocalVisits, Title in RemoveRecords.Title))

     

     

    BR

    Pontus

  • AndyDickson Profile Picture
    6 on at

    Many Thanks for your assistance with this and apologies for the delayed response - My only concern with the two stage approach involving collecting the posted records back is whether this would present some issues as the dataset in SharePoint grows into the thousands which I am expecting it to over time.

     

    I found an old thread which suggested using "If(IsEmpty" syntax to return a notification when Patch performed successfully. This appears to work well and I have experimented with changing the notification function to clear and it works. I just couldn't work out how to fit my Patch into the syntax as opposed to simply posting the "PowerApps Test" in the title of the SharePoint list as shown below.

     

    If(

        IsEmpty(

            Errors('PPM Visit Records',Patch('PPM Visit Records',Defaults('PPM Visit Records'),{Title:"PowerApps Test"}))

        ),

        Notify("Patch Successfully",NotificationType.Success),

        Notify("There is an error with your Patch function",NotificationType.Error)

    )

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!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 493 Most Valuable Professional

#2
11manish Profile Picture

11manish 479

#3
Haque Profile Picture

Haque 328

Last 30 days Overall leaderboard