Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Error Handling
Suggested answer

Patch related table with collection from another table.

(0) ShareShare
ReportReport
Posted on by
I have 3 tables - Employee, EmployeeSoftware, Software. Employee and Software have a one-to-many relationship with EmployeeSoftware and it is intended to be a bridge table. In my canvas app, I am creating a collection based on the software that is selected in a gallery. (gallery displays all software) I have a submit button that would ideally patch each selected Software and Employee to the EmployeeSoftware table. However, when trying to use a ForAll(collection, I get an error that EmployeeSoftwares is not accessible in this context.  
 
ForAll(SelectedItems,
Patch('EmployeeSoftwares', Defaults(EmployeeSoftwares) ....
 
 
Is there a better way I could achieve this outcome or how could I make the collection patch to a seperate table?
  • Suggested answer
    SwatiSTW Profile Picture
    SwatiSTW 358 Super User 2025 Season 1 on at
    Patch related table with collection from another table.
    The error "EmployeeSoftwares is not accessible in this context" usually occurs because this table might not be recognized in the context of the ForAll function or this table might not be properly added as a data source in your app. Try below solutions
    1. Ensure EmployeeSoftwares is added as a data source in your app
    2. Create a collection to store the selected software items. Assume you are working with a gallery named GallerySoftware, and it has a checkbox for selection.
    ClearCollect(
        SelectedItems,
        Filter(GallerySoftware.AllItems, CheckboxSelected.Value)
    );
    3. Store the currently selected employee in a variable. For example, if the current employee is determined by the logged-in user
    Set(
        CurrentEmployee,
        LookUp(Employees, Email = User().Email)
    );
    4. Use ForAll to loop through the collection and patch each selected software to the EmployeeSoftwares table. Use explicit field references to avoid ambiguity.
    ForAll(
        SelectedItems,
        Patch(
            EmployeeSoftwares,
            Defaults(EmployeeSoftwares),
            {
                Employee: CurrentEmployee,
                Software: ThisRecord
            }
        )
    );

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

Microsoft Kickstarter Events…

Register for Microsoft Kickstarter Events…

Announcing Our 2025 Season 1 Super Users!

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

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,318 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 65,111 Most Valuable Professional

Leaderboard

Featured topics