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/Patch not working
Power Apps
Answered

ForAll/Patch not working

(0) ShareShare
ReportReport
Posted on by 19

Hello - 

I'm struggling with Patching multiple related records.  Backend is Dataverse. This is a PowerApps for Teams canvas app.

 

In the database, amongst other things:

  1. A table named Patients that lists patient data (one)
  2. A table named Caseload that lists related data about which Patients are on individual providers' caseloads (many)

 

I have a collection of data called colPtUpdates - this is a stash of Patient records that have been updated on a form. I am saving these updated records to the database via Patch, no problem.

 

Next step would be to save some of the Patient information to the Caseload table.  This seems like it should be so simple, and I am referencing an example that I found here: How to bulk update records in PowerApps | Microsoft Power Apps

 

The code is attached.  The error it's getting is: "The specified column is not accessible in this context."

I've similarly tried just collecting related Caseload records in a collection with similar errors happening.  

I'm completely mystified.  

 

Does anyone have any thoughts about what I'm missing?  I'm sure it's a lot - PowerApps has not come easily to me...

 

Thanks,

Liz

Capture.JPG
Categories:
  • WarrenBelz Profile Picture
    156,576 Most Valuable Professional on at

    Hi @elodonnell ,

    Firstly please post any code also in Text - saves re-typing this end. Try this

    If(
     CountRows(colPtUpdates) > 0,
     Patch(
     Patients,
     colPtUpdates
     );
     ForAll(
     colPtUpdates As _Update,
     Patch(
     Caseloads,
     LookUp(
     Caseloads, 
     clPatient = _Update.Patient
     ),
     {clPatientName: _Update.ptName}
     )
     );
     Clear(colPtUpdates);
    );

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    MVP (Business Applications)   Visit my blog Practical Power Apps

  • elodonnell Profile Picture
    19 on at

    Hi, @WarrenBelz - 

     

    Thank you for the help, my apologies for image vs copy-able text.

     

    The code that you sent is at least not getting an error!  However, it only is updating the first related Caseloads record.  I think I understand that this is due to Lookup only returning one record - how do I update ALL related Caseload records?

     

    Thank you again very much for your time and help.

  • Verified answer
    elodonnell Profile Picture
    19 on at

    What actually seems to work is this: 

    If(CountRows(colPtUpdates) > 0,
    
     Patch(
     Patients,
     colPtUpdates
     );
    
     If(
     CountRows(colPtUpdates) > 0,
     Patch(
     Patients,
     colPtUpdates
     );
    
     ForAll(
     colPtUpdates As _Update,
     UpdateIf(
     Caseloads,
     clPatient.Patient = _Update.Patient,
     {
     clPtName: _Update.ptName
     }
     );
     );
    
     Clear(colPtUpdates);
    
     );
    
    );

     

    Thank you very much for getting me started in the right direction!

  • WarrenBelz Profile Picture
    156,576 Most Valuable Professional on at

    Hi @elodonnell ,

    Is the field clPatient in Caseloads a unique value for each record and does it always match the relevant Patient field in your collection?

  • elodonnell Profile Picture
    19 on at

    Hi @WarrenBelz , no - clPatient is NOT always unique for each record --> one Patient can be on the Caseload of providers from multiple disciplines.

  • WarrenBelz Profile Picture
    156,576 Most Valuable Professional on at

    @elodonnell ,

    I responded without seeing the solution - that is the direction I was heading with my question 

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

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 396 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 323

#3
WarrenBelz Profile Picture

WarrenBelz 193 Most Valuable Professional

Last 30 days Overall leaderboard