cancel
Showing results for 
Search instead for 
Did you mean: 

Patch - Referance a column name via a variable

Is that possible to make PowerApps can refer to a column via a variable?

 

I want to use "Patch" function to update column in Data Source. But the number of columns to be updated and columns name is not fixed. So it would be great of PowerApps to allow dynamically refer to a column.

 

 

For example, is it possible to replace the "DataField_8" below with dynamic variable such as "Dropdown2.Selected.Value"?

 

 
Patch(dbo_Update, LookUp(dbo_Update, ProductCode=Dropdown1.Selected.Value), {
    DataField_8 : TextInput1.Text
})
Status: Under Review

We hear you and appreciate your patience.  Unfortunately this is not easy for us to do.  Unlike VBA and other languages, Power Apps is strongly typed and named - everything is well established at compile time.  It's one of the fundamental principles of the product.  This allows us to detect more errors, optimize, and provide better intellisense during authoring.

 

Can you tell us more about the scenarios in which this would be helpful?  Some examples with code would be great.  Perhaps we can find a solution that addresses the need without making field names fully dynamic.

Comments
TjeerdteDuits
Regular Visitor

This is literally a showstopper. I have more than 50 columns i want to be able to edit using patch. Hardcoding these would cost way too much time, especially since these columns change over time. It would only be possible when users for example could select on of the required columns with a dropdown, and then automatically use this selected value in the patch function. 

JKandar
Frequent Visitor

Another use case for this:

 

I need a simple front end interface for users to input data into a SQL Server database.  This is a new database and tables will be added regularly.  Each table needs its own form in the Power App.  Each field in each table also needs to pass defined validation rules, which could include regex matching.  I am able to store all of this data, whether a field is valid, what field in the DB it corresponds to, the value in the field, etc. in a multi-tiered collection hierarchy.  

 

The idea is that whoever takes over the app in the future should be able to add a new form for a new DB table in minutes and not have to deal with laying out controls and adding validation logic, etc.  Following Reza's dynamic form using galleries tutorial, I have got it so that just at the press of a button, I can have one gallery that instantly swaps to whatever table is indicated in the button.  The owning developer can add a new table just by adding a button and setting a variable to the new table name.

 

The one problem is patching the form results back into the database without having to hard code every DB column into the patch statement.  Unfortunately, there's no way to generate a record variable with dynamically named columns (keys).  I have a 2 column table variable with columns "Key" and "Value", and ideally I'd like to iterate over this list and use the text string stored in the "Key" column as the record key, and feed that final record into a patch statement to add the record to my database.