cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
FredForest
Level: Powered On

Patch Azure SQL DB for new record

Hello,

I'm trying to create a new record in Azure SQL DB where I have a primary key with an IDENTITY property set. I'm using this kind of syntax:

Patch('myTable',Defaults('myTable'),{Id:Blank()},{field:something.Text},etc)

My problem:I'm getting the message that my ID field is obligatory and no record is created...

I've tried a few different syntax (without the Defaults, without the Blank) but I'm still not able to get it to work. Since this is about the most classic CRUD pattern there is, I'm guessing it is supported and I'm just doing something silly.

Anyone has a hint ?

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
FredForest
Level: Powered On

Re: Patch Azure SQL DB for new record

Hi @v-micsh-msft

 

I had indeed a problem with my { } as you noticed. But that wasn't the root cause.

 

I did some further investigation and the main issue was that my back-end was using a SEQUENCE object rather than an IDENTITY to generate the ID value in Azure SQL DB. Power Apps didn't seem to like that. I changed it to a regular IDENTITY and that did the trick.

 

For the Blank() function, I tried it after reading another thread on the forums relating to Patch and Azure SQL DB.

 

So, in the end, the correct answer was : using IDENTITY rather than SEQUENCE and using the syntax

Patch('MyTable', Defaults('MyTable'), {Field1:Input1.Text, Field2:Input2.Text, ...})

Thanks a lot for the prompt help!

 

View solution in original post

2 REPLIES 2
Community Support Team
Community Support Team

Re: Patch Azure SQL DB for new record

Hi @FredForest,

 

I think the issue here should be record format you specified under the Patch function.

Patch('myTable',Defaults('myTable'),{Id:Blank()},{field:something.Text},etc)

A single record is quoted by {}, so in the formula above, the formula is trying to create two records,and the second record 

{field:something.Text}

is without the required primary key, which is not allowed in PowerApps.

Besides, if you would like to generate one record, please specify the different fields in the record within one brace.

 

In addition, would you please explain a bit for:

{Id:Blank()}

Blank() function is not available to patch null values in such a scenario, and the ability to patch Null values is still under developing.

So I assume the workable formula should be:

Patch('myTable',Defaults('myTable'),{Id:Idstring,field:something.Text})

Regards,

Michael

Community Support Team _ Michael Shao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Highlighted
FredForest
Level: Powered On

Re: Patch Azure SQL DB for new record

Hi @v-micsh-msft

 

I had indeed a problem with my { } as you noticed. But that wasn't the root cause.

 

I did some further investigation and the main issue was that my back-end was using a SEQUENCE object rather than an IDENTITY to generate the ID value in Azure SQL DB. Power Apps didn't seem to like that. I changed it to a regular IDENTITY and that did the trick.

 

For the Blank() function, I tried it after reading another thread on the forums relating to Patch and Azure SQL DB.

 

So, in the end, the correct answer was : using IDENTITY rather than SEQUENCE and using the syntax

Patch('MyTable', Defaults('MyTable'), {Field1:Input1.Text, Field2:Input2.Text, ...})

Thanks a lot for the prompt help!

 

View solution in original post

Helpful resources

Announcements
firstImage

Microsoft Business Applications Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

firstImage

Demo Extravaganza Championship Voting Open

Voting Ends: October 30, 2019!

firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

Top Kudoed Authors
Users Online
Currently online: 356 members 5,166 guests
Please welcome our newest community members: