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 / Help with - button to ...
Power Apps
Unanswered

Help with - button to either not clear collection or remove the success records if error using ForAll and Patch

(0) ShareShare
ReportReport
Posted on by 2

Hello PowerApps Community,

*english is not my first language

 

I have an app that lists inventory and some data about each item. Its data source is a sharepoint list (biglist). I created a new screen to edit the list using 2 galleries: A(Inventory_Search_Gallery,biglist) - is to list all items and search in it. relevant columns are InventoryCount and Title

B(SelectedMaterialsGallery,SelectedMaterials) - is a collection created by OnSelect in gallery A. Gallery B is ment for editing in bulk spesific records . collect function is:

Collect(
SelectedMaterials,
{
ID: GUID(),// Generate a unique ID using the GUID() function
ItemName: Inventory_Search_Gallery.Selected.Title,
Quantity: Inventory_Search_Gallery.Selected.InventoryCount,
startQuantity: Inventory_Search_Gallery.Selected.InventoryCount,
ReadyToSave: false
}
)

In Gallery B I have some inputs, toggles and buttons to manage each record. I dont know if its relevant, but if it is ill share by request.

When editing is done I have a button to patch biglist that works fine but is lacking:

ForAll(
SelectedMaterials,
If(ThisRecord.ReadyToSave=false,
Notify("Please confirm for row " & ThisRecord.ItemName,NotificationType.Error),
Patch(
biglist,
LookUp(biglist, ItemName = ThisRecord.Title),
{ InventoryCount: ThisRecord.Quantity }
)
)

);
Clear(SelectedMaterials)

 

My problam is that SelectedMaterials clears even if an error is triggered. I want it to either: remove the success records (keeping the error records to be fixed) or not clear the collection.

 

So I tried to use bing for help. this is what i got: spoiler (powerapps give me an invalid argument for clearcollect)

ClearCollect(

    ErrorRecords, // Initialize the ErrorRecords collection

    ForAll(

        SelectedMaterials, // Loop through each record in SelectedMaterials

        If(

            ThisRecord.ReadyToSave = false, // Check if ReadyToSave is false

            Notify("Please confirm for row " & ThisRecord.ItemName, NotificationType.Error), // Show error message and add record to ErrorRecords

            If(

                !IsBlank(LookUp(biglist, ItemName = ThisRecord.Title)), // Check if record exists in biglist

                Patch(

                    biglist, // Update the existing record in biglist

                    LookUp(biglist, ItemName = ThisRecord.Title),

                    { InventoryCount: ThisRecord.Quantity }

                )

            )

        )

    )

);




If(

    CountRows(ErrorRecords) = 0, // If no error records, clear SelectedMaterials

    Clear(SelectedMaterials)

)

Any ideas?

Categories:
I have the same question (0)
  • workingonpowera Profile Picture
    2 on at

    update: what i ended up doing is createing a new gallery for errorrecords and had lots of duplication for buttons and such. edited the buttons to acomodate for 2 galleries

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 358 Most Valuable Professional

#2
11manish Profile Picture

11manish 214 Super User 2026 Season 2

#3
Mohsin Ali Profile Picture

Mohsin Ali 185

Last 30 days Overall leaderboard