Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Building Power Apps
Answered

Updating database from collection in a ForAll

(1) ShareShare
ReportReport
Posted on 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 at
    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 at
    Re: Updating database from collection in a ForAll

    Can you say what you changed?

  • mmbr1606 Profile Picture
    12,104 Super User 2025 Season 1 on at
    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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,603 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 65,946 Most Valuable Professional

Leaderboard