Skip to main content

Notifications

Power Apps - Building Power Apps
Answered

PATCH to SQL not working

(0) ShareShare
ReportReport
Posted on by 56

Hi there, 

Still in the process of building out my app. 

I'm trying to PATCH a new record to SQL but I cant get the right formula when dropdowns are involved. 

I have tried .Selected.Text, .Selected.Value, .Selected.Result, .Selected and keep getting errors.

The only time the code doesn't throw an error is when I use these values highlighted.

kpechal150_5-1691439160708.png

 

Which come from this code below where I am adding a blank to the dropdowns. But nothing happens when I run the Patch code since that's a reference to the blank and not the actual selected value. But .Selected.DataTypes isnt an option...

kpechal150_2-1691438086875.png

 

Example Selected.Value not working -

kpechal150_4-1691438964701.png

 

 

What am I missing here? Please help. Let me know if you need more info.

Note - the SQL table PK is an identity column that auto generates. 

 

Follow up question - 

If I can get this working to create new records, I want to then create a variable that once saved to SQL, the identity SQL number "Inventory ID" is returned. Can this be worked into the same code as above?

kpechal150_6-1691439567081.png

 

 

Code for editing:

 

Patch(EXPL_inventorytest,
Defaults(EXPL_inventorytest),
{
MediaBarcode: tMB.Text,
DataType: ddDataType.Selected,
Country: ddCountry.Selected,
MediaType: ddMediaType.Selected,
MediaNumber: tMediaNumber.Text,
Location: ddLocation.Selected,
DigitalFormat: ddDigitalFormat.Selected,
DataDescription: tDataDescription.Text,
RecordCreatedBy: tRecordCreatedBy.Text,
RecordCreatedDate: dpRecordCreatedDate.SelectedDate
}
)

 

 

  • Verified answer
    kpechal150 Profile Picture
    kpechal150 56 on at
    Re: PATCH to SQL not working

    Turns out it was an issue with SQL. I had a trigger on my table for recordupdatedby and recordupdateddate. Deleted the trigger and code ran perfectly. 

  • kpechal150 Profile Picture
    kpechal150 56 on at
    Re: PATCH to SQL not working

    I have found the error and made a few modifications - 

    The issue was with the dropdown Items code where I was trying to include a blank value. I have changed the dropdown code to this:

    kpechal150_6-1691519371716.png

     

    And updated my OnSelect code of my save button to this: 

    kpechal150_7-1691519400611.png

     

    However, now when I run it it looks like its processing but ultimately gives me this error and no other information:

    kpechal150_8-1691519451864.png

     

    There's no formula errors but there are some performance errors. Though It wont let me see the entire message!? 

    kpechal150_9-1691519617484.png

    kpechal150_10-1691519663831.png

    So I update my dropdown code to:

    kpechal150_11-1691519737277.png

    And I get same error with no information as to why - 

    kpechal150_13-1691519870624.png

     

    Could this be an issue with SQL and not PowerApps?

     

    Thanks!

     

  • cwebb365 Profile Picture
    cwebb365 3,294 on at
    Re: PATCH to SQL not working

    What data types are the columns in SQL you are writing to? Have you tried just plugging in dummy "Test" text there to make sure it works? 

     

    Hover over the ungroup or select it and what all is returning? Is it multiple columns? Could be .Results but if you have multiple coumns coming in It'll be different than just value as there is multiple rows. 

     

    As for the returning the ID, you can just use the Patch(Patchcode).ID to get the ID back from it. So you can put it in a variable when you execute the patch, so Set(varRecordID, Patch(Patchcode).ID) for example will save the ID into the varRecordID variable. 

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 145,580

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,909

Leaderboard