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 / Patching the 'parent' ...
Power Apps
Answered

Patching the 'parent' table from a gallery

(0) ShareShare
ReportReport
Posted on by 716 Moderator

So the section of code that is about to follow is on the OnSelect of an Icon in a gallery. 

The first section patches a record in a list if varGalEdit is true. That same variable helps control visibility of a bunch of things based on current user etc.

This works correctly as does the reset of varGalEdit immediately below.

The next IF statement is trying to determine if 'SPIFF - Approvals' has records that match the number of approvers with the same approve_level. It would honestly be better if that IF statement didn't just compare counts but actually verified that there was a specific record in 'SPIFF - Approvals' for each 'SPIFF - Approvers'.Approver where the Approve_Level matched the Approve_Level from galItems but for now I'm satisfied using CountRows since the UI and input controls ensures the right results even though it's really not right.

I have a problem there I can't figure out to start with. Approver.Email = Approver is wrong. This specific statement:

Filter(
 'SPIFF - Approvals',
 Approver.Email = Approver
 && PositionID = galItems.Selected.ID
 )

I think the UpdateContext statements are correct but until I can get the upper part working, they aren't even processing.

Then after all of this happens, I want to Patch the 'SPIFF - Requests' record which is galItems.Selected and set the Approve_Level based on the results from the CountRows comparison.

If(
 varGalEdit = true,
 Patch(
 'SPIFF - Approvals', // The target data source
 LookUp(
 'SPIFF - Approvals',
 ID = galApprovals.Selected.ID
 ), // Identify the specific record
 {
 Comments: txtApproverComment.Text,
 // Update or set the value of Comments column
 // Add more columns and values as needed
 Status: rdoApproveEdit.Selected
 // Update or set the value of Status column
 // Add more columns and values as needed
 }
 ),
 Set(
 varGalEdit,
 false
 ),
 If(
 CountRows(
 Filter(
 'SPIFF - Approvers',
 Approve_Level = galApprovals.Selected.Approval_Level
 )
 ) = CountRows(
 Filter(
 'SPIFF - Approvers',
 Approve_Level = galApprovals.Selected.Approval_Level &&
 !IsEmpty(
 Filter(
 'SPIFF - Approvals',
 Approver.Email = Approver
 && PositionID = galItems.Selected.ID
 )
 )
 )
 ),
 UpdateContext(
 {
 varNewApprovalLevel: galItems.Selected.Approval_Level + 1
 }
 ),
 UpdateContext(
 {
 varNewApprovalLevel: galItems.Selected.Approval_Level
 }
 )
 ),
 Patch(
 galItems, // The target data source (e.g., SharePoint list)
 galItems.Selected, // Identify the specific record
 {
 Approve_Level: varNewApprovalLevel
 // Update or set the value of Approval_Level column
 // Add more columns and values as needed
 }
 )
)

 

Thanks in advance to whomever takes the time to read this.

 

Categories:
I have the same question (0)
  • DCHammer Profile Picture
    716 Moderator on at

    Forget reading the OP. I made some changes that have been at least partially successful.

     

    Everything now gets past the interpreter. It no longer thinks there are errors in this and it will proc. But it's not completing the final Patch and updating the record. 

     

    I think I have a problem with my nested IFs but I can't figure it out. My assumption is that the If statement is evaluating such that it's not even processing the final Patch statement. I know it works up to and including the UpdateContext statements. Because I manually create the data conditions for the CountRows comparison to succeed and/or fail, the context variable is setting correctly. But regardless of that outcome, the final Patch doesn't execute.

     

    If(
     varGalEdit = true,
     Patch(
     'SPIFF - Approvals',// The target data source (e.g., SharePoint list)
     LookUp(
     'SPIFF - Approvals',
     ID = galApprovals.Selected.ID
     ),// Identify the specific record
     {
     Comments: txtApproverComment.Text,
     // Update or set the value of Comments column
     // Add more columns and values as needed
    Status: rdoApproveEdit.Selected
     // Update or set the value of Status column
    // Add more columns and values as needed
     }
     ),
     Set(
     varGalEdit,
     false
     ),
     If(
     CountRows(
     Filter(
     'SPIFF - Approvers',
     Approve_Level = varItem.Approval_Level
     )
     ) = CountRows(
     Filter(
     'SPIFF - Approvals',
     Approve_Level = varItem.Approval_Level && PositionID = varItem.ID
     )
     ),
     UpdateContext({varNewApprovalLevel: varItem.Approval_Level + 1}),
     UpdateContext({varNewApprovalLevel: varItem.Approval_Level + 0})
     ),
     Patch(
     'SPIFF - Requests', // The target data source (e.g., SharePoint list)
     LookUp(
     'SPIFF - Requests',
     ID = varItem.ID
     ), // Identify the specific record
     {
     Approval_Level: varNewApprovalLevel
     // Update or set the value of Approval_Level column
     // Add more columns and values as needed
     }
    )
    
    );
  • DCHammer Profile Picture
    716 Moderator on at

    So it occurred to me on my drive home that I need to separate the first IF statement from the second. This isn't a single transaction. The first If processes regardless of the outcome of the second. So I'll 'commit' the change to the gallery item with the first If and close that loop and reset the varGalEdit variable.

    Then process the second If to determine if the records are such that the value on the varItem needs to be patched.

    I also realize as I'm typing this that it was always going to fail the way it's currently structured even if the nested Ifs were correct.

    Since this same code is what actually creates or updates the approval records that are then later analyzed for existence, it was going to fail when the last person in the flow created their approval.

    I'll update this later today with what I manage to make work.

  • Verified answer
    DCHammer Profile Picture
    716 Moderator on at

    Here is what I finally came up with. I'm sure there are far cleaner ways to make this work but it does so I'm leaving it alone.

    I didn't originally have that last Patch statement inside an If. Since the context variable was being set appropriately above, patching the record always resulted in the same value but in a bunch of cases would create unnecessary updates. So I changed it. 

    If I was really concerned about data integrity, I should modify the CountRows section to actually determine if the Users with an Approve_Level that matches the varItem have their own individual records in the Approval list but I have enough control around who can create approval records that using CountRows is going to always work.

     

    If(
     varGalEdit = true,
     Patch(
     'SPIFF - Approvals',// The target data source (e.g., SharePoint list)
     LookUp(
     'SPIFF - Approvals',
     ID = galApprovals.Selected.ID
     ),// Identify the specific record
     {
     Comments: txtApproverComment.Text,
     // Update or set the value of Comments column
     // Add more columns and values as needed
    Status: rdoApproveEdit.Selected
     // Update or set the value of Status column
    // Add more columns and values as needed
     }
     ),
     Set(
     varGalEdit,
     false
     )
    );
    If(
     CountRows(
     Filter(
     'SPIFF - Approvers',
     Approve_Level = varItem.Approval_Level
     )
     ) = CountRows(
     Filter(
     'SPIFF - Approvals',
     Approve_Level = varItem.Approval_Level && PositionID = varItem.ID
     )
     ),
     UpdateContext({varNewApprovalLevel: varItem.Approval_Level + 1}),
     UpdateContext({varNewApprovalLevel: varItem.Approval_Level + 0})
    );
    If(
     varNewApprovalLevel <> varItem.Approval_Level,
     Patch(
     'SPIFF - Requests',// The target data source (e.g., SharePoint list)
     LookUp(
     'SPIFF - Requests',
     ID = varItem.ID
     ),// Identify the specific record
     {Approval_Level: varNewApprovalLevel
     // Update or set the value of Approval_Level column
    // Add more columns and values as needed
    }
     );
     UpdateContext ({varNewApprovalLevel: Blank()})
    );
    If(
     varGalEdit = false,
     Set(
     varGalEdit,
     true
     ),
     Set(
     varGalEdit,
     false
     )
    )

     

    Kinda proud of figuring this one out on my own. Thanks for attending.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 549 Most Valuable Professional

#2
Kalathiya Profile Picture

Kalathiya 225 Super User 2026 Season 1

#3
Haque Profile Picture

Haque 224

Last 30 days Overall leaderboard