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
Dual Super User
Dual 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

 

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
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

365 EduCon 768x460.png

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Users online (4,014)