cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
EszuuPA
New Member

Patch is asking for required column

I am trying to allow users of my app to add new records to an Azure SQL database, using the following code:

 

 

Patch(
    NameOfTable;
    Defaults(NameOfTable);
    {
        column1: nameOfVar;
        //requiredColumn: Value(lblRequiredColumn.Text);
        column2: comboboxColumn2.Selected.valueToStore;
        column3: inputtextColumn3.Text
    }
)

 

The requiredColumn has an id with an integer value. Ideally, I don't want to let the client (PowerApps) generate this number. It's a lot more robust if the server handles this. But the form only works if I let PowerApps calculate the ID, using this code:

 

Last(nameOfTable).requiredColumn+1

 

 

When using the code above (with the column commented out) PowerApps says the column is required. This surprises me, because according to the documentation the data source should generate the ID automatically.

 

How can I make the code above work? Should I change anything in the PowerApp, or should I change something in the column settings in the SQL table?

1 ACCEPTED SOLUTION

Accepted Solutions
timl
Super User
Super User

@EszuuPA 

 

I've looked at the Patch documention that you referenced and I understand the confusion that it can cause. With SQL Server, the database will generate the ID value automatically, only if the column is defined as an identity column.

 

I suspect the problem is that your required column doesn't have the identity setting enabled. Therefore, the first thing I'd do is to check that. If identity is disabled and you enable it, you'll need to refresh the table in Power Apps for it to take effect. Sometimes, it can take a while for Power Apps to recogise these types of change, so you may need to wait about 30mins.

 

timl_0-1631179612627.png

 

View solution in original post

3 REPLIES 3
gabibalaban
Super User
Super User

@EszuuPA ,

Based on your scenario, I think that the best way to solved the issue is by modifying the table definition on SQL server side.

If your column will be auto-calculated in SQL, I don't see the reason to be also required because the server will take care to fill on each new record you create.

In PowerApps as the column is not required anymore, you can forget about it when you develop your form (delete the datacard created for this column).

Hope it helps !

timl
Super User
Super User

@EszuuPA 

 

I've looked at the Patch documention that you referenced and I understand the confusion that it can cause. With SQL Server, the database will generate the ID value automatically, only if the column is defined as an identity column.

 

I suspect the problem is that your required column doesn't have the identity setting enabled. Therefore, the first thing I'd do is to check that. If identity is disabled and you enable it, you'll need to refresh the table in Power Apps for it to take effect. Sometimes, it can take a while for Power Apps to recogise these types of change, so you may need to wait about 30mins.

 

timl_0-1631179612627.png

 

View solution in original post

EszuuPA
New Member

Thanks, both of your answers helped me in the right direction. Since it was a migrated legacy database it turned out the column was not even required, so it could simply be deleted. It now works like a charm!

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Users online (1,663)