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 / ForAll, UpdateIf & Pat...
Power Apps
Answered

ForAll, UpdateIf & Patch based on a collection doesn't update my list

(0) ShareShare
ReportReport
Posted on by 35

Hello Everyone,

 

I've never met this kind of issue before and I don't know how to solve it.

Purpose of my code is to update List data row into a specific column based on information into a collection.

 

The code which should works for is this operation would be this one :

ForAll(

    MyCollection,
    Patch(
        'MyList1',
        LookUp('MyList1', ID = ThisRecord.ID),
        {
            Quantity: LookUp('MyList1', ID = ThisRecord.ID, Quantity) - ThisRecord.Quantity
        }
    )
)
For an unknown reason, ID = ThisRecord.ID is not recognized and give an error code like "Error when trying to retrieve data from server"
So I changed = by In function.
No error but the update is made into all my list and quantity doesn't match
 
I tried to use UpdateIf like below
ForAll(
    MyCollection,
    UpdateIf('MyList1', ID in MyCollection.ID,
        {
            Quantity: LookUp('MyList1, ID in ThisRecord.ID, Quantity) - ThisRecord.Quantity
        }
    )
)

The IDs in my collection are updated in my list, but the system updates the quantity column with a number that makes no sense. I tried using the equals sign (=) and the "in" function, but the results did not improve.

 

I don't understand why my initial code (First into this topic) doesn't work with the equals sign (=). To me, it seems like the best way to update my list. Has anyone encountered this situation before and can offer help to correct my code?

 

Thanks in advance for your assistance.

 
 
Categories:
  • Verified answer
    AaronKnox Profile Picture
    514 Super User 2024 Season 1 on at

    Hi, @Powertiti ,

    At some point I'm going to write a blog post titled 'Why ForAll/ThisRecord is EVIL' 😈 :  You should always use the As operator with every ForAll(), no matter how simple the code. 

     

    • For complex, nested ForAlls, the As operator is required. 
    • For even a simple ForAll, the As operator makes it easier to read since you get to rename ThisRecord with whatever might help code readability.

     

    ForAll(
     MyCollection As _myColLoop,
     Patch(
     'MyList1',
     LookUp('MyList1', ID = _myColLoop.ID),
     {
     Quantity: LookUp('MyList1', ID = _myColLoop.ID, Quantity) - _myColLoop.Quantity
     }
     )
    )

     

    Hope this helps!

    Aaron

  • Powertiti Profile Picture
    35 on at

    Thank you very much Aaron,

    I just got back from a break and I had also thought about using the AS function. It's a function I rarely use, but indeed, it works perfectly.

    Thank you so much for your quick response. Have a great day!

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
11manish Profile Picture

11manish 409 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 328

#3
WarrenBelz Profile Picture

WarrenBelz 252 Most Valuable Professional

Last 30 days Overall leaderboard