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 Gallery to SQ...
Power Apps
Answered

Patching Gallery to SQL Table

(0) ShareShare
ReportReport
Posted on by 84

Hi,

 

In my app I am trying to update records in my SQL data source from a gallery. I am allowing the user to edit fields in a line and want to patch any field they might update to the corresponding record in SQL. Below, is my update code and the screen from my app. I am getting an error that the record is not found when I run the update. However, if I create a gallery with the same filter, I find my record. 

 

Save Button On Select:

Update(TABLE, First(Filter(TABLE, ID = Value(IDLabel.Text) && AXIS = Text(varAxis) && SITE = varSite && SCENARIO_ID = varScenarioID)), {ID: Value(IDLabel.Text), AXIS: Text(varAxis),SITE: varSite, SCENARIO_ID: varScenarioID, START_DATE: DateTimeValue(TextInput1.Text), END_DATE: DateTimeValue(TextInput2.Text)})

 

DeeCiii15_0-1674242914313.png

 

 

 

 

Categories:
I have the same question (0)
  • Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    @DeeCiii15 

    Patch(TABLE, ThisItem, {ID: Value(IDLabel.Text), AXIS: Text(varAxis),SITE: varSite, SCENARIO_ID: varScenarioID, START_DATE: DateTimeValue(TextInput1.Text), END_DATE: DateTimeValue(TextInput2.Text)})
  • DeeCiii15 Profile Picture
    84 on at

    Hi,

     

    Thanks for the reply. I tried your code and I'm getting the same response "The specified record was not found."

  • Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    @DeeCiii15 

    I am assuming that the ID is the Primary key of your table so try this

     

    Patch(TABLE, LookUp(TABLE,ID=ThisItem.ID), {ID: Value(IDLabel.Text), AXIS: Text(varAxis),SITE: varSite, SCENARIO_ID: varScenarioID, START_DATE: DateTimeValue(TextInput1.Text), END_DATE: DateTimeValue(TextInput2.Text)})

     

     I'm no SQL user but for this to work, you need to create a constraint on the Primary key of the table.   https://www.w3schools.com/sql/sql_primarykey.ASP 

  • DeeCiii15 Profile Picture
    84 on at

    I tried that code also, but I'm getting a syntax error saying Patch has some unsupported functions related to the Lookup.  (below)

    My primary key is setup as a constraint key in SQL Server using a combination of (ID, Site, Axis and ScenarioID)

     

    DeeCiii15_0-1674247497093.png

     

     

  • Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    @DeeCiii15 

    That is likely the problem.  PowerApps works better with a single ID as the primary key.  @timl   is much more familiar with sql than I am. 

  • DeeCiii15 Profile Picture
    84 on at

    Thanks for your help @Drrickryp Do you have any thoughts @timl ? Would it be better to do this with a called procedure directly to SQL?

  • Verified answer
    timl Profile Picture
    37,229 Super User 2026 Season 1 on at

    Hi @DeeCiii15 

    Rather than specifying the target record with a call to LookUp, you should be able to just specify the combination PK values.

    I'd try the following to see if that works any better:

    Patch(SCENARIO_TABLE, 
     {
     C_SLOT_ID:Value(SlotIDLabel.Text), 
     C_AXIS:Text(varFilterAxis), 
     C_PROD_SITE_PDP:varFilterSite, 
     SCENARIO_ID:parmScenarioID
     },
     {
     C_PROD_START_DATE: DateTimeValue(ProdStart.Text), 
     C_PROD_END_DATE: DateTimeValue(ProdEnd.Text)
     }
    )
    

     

     

  • DeeCiii15 Profile Picture
    84 on at

    that worked perfect thanks!

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

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 316 Most Valuable Professional

#2
11manish Profile Picture

11manish 242

#3
Valantis Profile Picture

Valantis 198

Last 30 days Overall leaderboard