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

Community site session details

Session Id : G4ctjQU2+yyUU1+6InHYgs
Power Apps - Building Power Apps
Answered

Updating database from collection in a ForAll

Like (1) ShareShare
ReportReport
Posted on 12 Jul 2024 13:18:56 by 36

Hi all

 

I have a collection, allowing user to update all data then save all.

I use a ForAll to add or update all. However, the update only updates the first record with data from the last record.

Seems like ThisRecord.id is from first and .name is from last.

 

What is wrong here?

 

    ForAll(palletList,        
        If(ThisRecord.id=Blank(),
            Notify(Concatenate("Pallet add", ThisRecord.item),NotificationType.Success,500);
            Patch(outbound_pallets, Defaults(outbound_pallets),
                { pallet_id: ThisRecord.pallet_id,
                item: ThisRecord.item,
                quantity: ThisRecord.quantity,
                comment: ThisRecord.comment,
                trip_id: tripList.Selected.id }),
            // else
            Notify(Concatenate("Pallet update ", ThisRecord.id, ",", ThisRecord.item, ",",ThisRecord.quantity),NotificationType.Error,500);
            Patch([@outbound_pallets], LookUp(outbound_pallets, id=ThisRecord.id),
                { pallet_id: ThisRecord.pallet_id,
                item: ThisRecord.item,
                quantity: ThisRecord.quantity,
                comment: ThisRecord.comment,
                trip_id: tripList.Selected.id });
        );
    );
 
  • Verified answer
    SonnichJensen Profile Picture
    36 on 12 Jul 2024 at 13:52:12
    Re: Updating database from collection in a ForAll

    I nailed it.

    ThisRecord refers to the item it is in, so ThisRecord within the LookUp is is for the present record within the LookUp. Therefore id=ThisRecord.id is always true.


    The solution comes with the keyword As

     

    ForAll(palletList As pl,
    ...
                // else
                Patch([@outbound_pallets], LookUp(outbound_pallets, id=pl.id),
                    { pallet_id: pl.pallet_id,
                    item: pl.item,
                    quantity: pl.quantity,
                    comment: pl.comment,
                    trip_id: tripList.Selected.id });
            );
        );
  • SonnichJensen Profile Picture
    36 on 12 Jul 2024 at 13:48:20
    Re: Updating database from collection in a ForAll

    Can you say what you changed?

  • mmbr1606 Profile Picture
    13,494 Super User 2025 Season 2 on 12 Jul 2024 at 13:33:20
    Re: Updating database from collection in a ForAll

    hey @SonnichJensen 

     

    can u try this:

    ForAll(palletList,
     If(IsBlank(ThisRecord.id),
     Notify(Concatenate("Pallet add: ", ThisRecord.item), NotificationType.Success, 500);
     Patch(outbound_pallets, Defaults(outbound_pallets),
     {
     pallet_id: ThisRecord.pallet_id,
     item: ThisRecord.item,
     quantity: ThisRecord.quantity,
     comment: ThisRecord.comment,
     trip_id: tripList.Selected.id
     }),
     Notify(Concatenate("Pallet update: ", ThisRecord.id, " Item: ", ThisRecord.item, " Qty: ", ThisRecord.quantity), NotificationType.Information, 500);
     Patch(outbound_pallets, LookUp(outbound_pallets, id = ThisRecord.id),
     {
     pallet_id: ThisRecord.pallet_id,
     item: ThisRecord.item,
     quantity: ThisRecord.quantity,
     comment: ThisRecord.comment,
     trip_id: tripList.Selected.id
     });
     )
    );
    

     

    Let me know if my answer helped solving your issue.

    If it did please accept as solution and give it a thumbs up so we can help others in the community.



    Greetings

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

Telen Wang – Community Spotlight

We are honored to recognize Telen Wang as our August 2025 Community…

Announcing our 2025 Season 2 Super Users!

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

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 637 Most Valuable Professional

#2
stampcoin Profile Picture

stampcoin 570 Super User 2025 Season 2

#3
Power Apps 1919 Profile Picture

Power Apps 1919 473

Loading complete