cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Frequent Visitor

Patch function - Field required error even though field value is provided

In my app's OnStart PowerApps is telling me that a Patch command is failing due to a "Field required" error, i.e. I am not providing a value for a non-nullable column in my database (Azure SQL). As you can see below:

Field Required - ThisApplicationId.png

 

 

 

 

 

 

 

I know you are going to ask whether the ThisApplicationId variable has a value, so to make things clearer here it is with a constant value provided:

Field Required - Constant.png

 

This is an export of an app that works fine in our production tenancy. I am getting this error in a trial environment in our non-prod tenancy, where I am looking to perform some testing. However because the AppStart process is failing, my tests are failing at the first hurdle.

 

I am also getting another Patch field required error elsewhere in the app, on a date field, despite that date being set to a date picker which definitely has a value, but that's another post for another day.

3 REPLIES 3
Highlighted
Community Support
Community Support

Hi @ESGary ,

Could you tell me whether do you want to create a new record or edit an existing record?

Actually,  the right syntax of Patch function should be like:

Patch(table,Defaults(table),{....})   //create a new record

Patch(table,the item that you want to edit,{..})    //edit an existing record

While your formula is like: Patch(table,{Id:Blank()},{.....})

{Id:Blank()} can not represent an item that need to be edit.

Usually, we use LookUp() or First(Filter()) to represent the item that will be edit.

So if you want to create a new record, please try: 

Patch(table,Defaults(table),{....})

If you want to edit an existing record, please try: 

Patch(table,LookUp(table,Id=Blank()),{...})

 

What's more, please make sure that your SQL table has primary key. If it doesn't have primary key, you can not update this table in PowerApps.

Here's a doc about Patch function for your reference:

https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-patch

 

 

Best regards,

Community Support Team _ Phoebe Liu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Highlighted

Thanks for taking the time to reply - I appreciate it.

 

Passing in a blank Id as I do (Id is the primary key) tells Patch to create a new record, and it's a pattern I use a lot. This works and has worked in production for a long time. I am just getting this error in my test environment for no apparent reason. My suspicion is that the error message being displayed is incorrect and covering up some other sort of error, but I have no way of proving that.

 

Anyway, using your preferred syntax I still get the same error:

Field Required - Using Defaults.png

Highlighted
Frequent Visitor

OK so I seem to have solved this. As expected the error message was misleading - it was actually the UserId value that was missing (earlier in my script that value wasn't loading correctly for some reason).

 

So I guess the question is why was PowerApps claiming it was the ApplicationId that was missing?

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Community Highlights

Community Highlights

Check out the Power Platform Community Highlights

Top Solution Authors
Top Kudoed Authors
Users online (7,870)