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
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.
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
thirdimage

Power Automate Community User Group Member Badge

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

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

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