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 / Patch function patchin...
Power Apps
Answered

Patch function patching row below

(0) ShareShare
ReportReport
Posted on by 59

I'm having a problem with my patch function. There is an if statement that determines whether or not the patch function creates a new row or updates an existing row in my table. Creating a new row works, but for some reason when updating an existing row the row below the one selected in my gallery control is being modified rather than the row that was selected in the gallery. Here is the code I am using to patch the table:

 

 

UpdateContext({tempsave:1}) ; If(NewGate = 2, Patch('datasource', {cpcId:Gallery1.Selected.cpcId}, SummaryFormLCG1.Updates, PlanningFormLCG1.Updates, FinancialsFormLCG1.Updates), Patch('datasource', Defaults('datasource'), SummaryFormLCG1.Updates, PlanningFormLCG1.Updates, FinancialsFormLCG1.Updates))

 

 

 

Categories:
I have the same question (0)
  • quinncain Profile Picture
    59 on at

    It could also be noted that cpcId is the primary key. It is incremental and generated whenever a new row is added to the table.

  • Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    @quinncain 

    UpdateContext({tempsave:1}); 
    If(
     NewGate = 2, Patch(
     'datasource', cpcId=Gallery1.Selected.cpcId, SummaryFormLCG1.Updates, 
     PlanningFormLCG1.Updates, 
     FinancialsFormLCG1.Updates
     ),
     Patch(
     'datasource', Defaults('datasource'), SummaryFormLCG1.Updates, 
     PlanningFormLCG1.Updates, 
     FinancialsFormLCG1.Updates
     )
    )
  • quinncain Profile Picture
    59 on at

    @Drrickryp 

    Thank you formatting this in a more readable way. I am having trouble with this still though. There is an error on "cpcId=Gallery1.Selected.cpcId". The error I got on this was "cpcId" not recognized. I created a datacard on my one of the forms that is passed the cpcId of the row selected from the gallery, and realized that comparing that to the database would just be a boolean true or false and not a record being selected from the table. How can I select a record/row based on matching the cpcId of the form being edited to a row in the table?

     

  • Verified answer
    Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    @quinncain 

    It should be Lookup(datasource, cpcid=Gallery1.Selected.cpcid) or maybe just

    Lookup(datasource, ID=Gallery1.Selected.ID)

  • quinncain Profile Picture
    59 on at

    This works. I feel really dumb; Gallery1 is a different gallery for a different function on my app, and since I wasn't selecting from there the updates just kept posting to the same row. Thank you for your help and being so patient.

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!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Vish WR Profile Picture

Vish WR 1,045

#2
Valantis Profile Picture

Valantis 675

#3
11manish Profile Picture

11manish 592

Last 30 days Overall leaderboard