Skip to main content

Notifications

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 230 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

November 2024 Newsletter…

November 2024 Community Newsletter…

Community Update Oct 28…

Power Platform Community Update…

Tuesday Tip #9 Get Recognized…

Welcome to a brand new series, Tuesday Tips…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 143,867

#2
RandyHayes Profile Picture

RandyHayes 76,308

#3
Pstork1 Profile Picture

Pstork1 64,174

Leaderboard

Featured topics