cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Advocate II
Advocate II

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
Advocate II
Advocate II

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
Highlighted
Community Support
Community Support

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.
Advocate II
Advocate II

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
August 2020 Community Challenge: Can You Solve These?

August 2020 Community Challenge: Can You Solve These?

We're excited to announce our first cross-community 'Can You Solve These?' challenge!

secondImage

Return to Workplace

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

secondImage

Super Users Coming in August

We are excited for the next Super User season.

secondImage

Community User Group Member Badges

FIll out a quick form to claim your community user group member badge today!

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (8,093)