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
KJH1138
Frequent Visitor

This would be an extremely useful feature.  I've spent a full day trying to find a more efficient way to accomplish something and it turns out my 'hack' (massive Switch formula) is the best approach.  Especially frustrating as the referenced column structure in my app is somewhat fluid* so I have to update the formula every-time we add a column or consolidate columns.

 

*We are trying to normalize the various customer questionnaires our teams use (multiple redundancies and differences in term definitions) into a single SharePoint list.  The App allows users to select the form they want to use and it only displays the questions relevant to them (with answers pre-populated if someone already asked the question in a different forum).  Over time we plan to consolidate questions (columns) and add new questions (columns) as new requirements arise

Anonymous
Not applicable

Using dynamic column names will not violate you beautiful world defined by “Power Apps is strongly typed and named - everything is well established at compile time.” The reason is simple, column names are strings, so any variable of type string can be used as a column name. Simple to incorporate in PowerApps world. No?

KyleJ
Helper II

@GregLi 

 

In addition to dynamic patch functions, Having dynamic columns allows something so simple as a dynamic filtering interface for our data in our apps. 

A large majority of the "power apps" that are created for my organization are for small projects, including a BUNCH of "trackers" (tracking current status of various different processes within our company) These trackers often come with galleries full of table-layout data. I understand how to create switch statements that allow for this. They work fine, as long as our processes NEVER change (sometimes that may hold true. But in today's world, this is becoming less and less true) 

Realistically, processes change, and therefore, so do some of the options/statuses in our trackers. Not drastically, lets just add a new "Status" and call it "Returned For More Info" I would like to just add it to my list of dropdown options in my sharepoint list. and add "Return for more info" to the existing list of: "New","Accepted","Rejected"

Now, (because i populated a gallery Items with Choices(souce.status) ) My gallery instantly reflects this change! and now i have a new status i could potentially click on in my gallery to filter by (because before, if i click "New" it filtered for new, because that's in my switch statement, So I click on my dynamically generated "Return for more info" button, but my table breaks and i see absolutely no data. That's because the option "Returned for More Info" doesn't exist in my hard-coded switch statement. That's a poor breaking point. I have set up an almost entirely dynamic app that can handle dramatic changes without ever being needed to touch by a developer again. But Now my Sharepoint guys not only have to make changes to the sharepoint list to effect the app, but then i STILL have to open powerapps in dev mode and make changes to that switch statement, when i shouldn't have to. I should be able to update my sharepoint dropdown column options, and let it fully reflect and trickle through my app. 

FlowRunner
Regular Visitor

MUST have to build multi-lingual apps and enable the user to add different languages on the fly...

HansHeintz
Post Patron

Since a table can be a property of a component: different tables might be used with different field names.

If I use a switch statement powerapps branching the different possible field names, powerapps will just say it does not know the names. If I could reference de fields by string, powerapps would not get mad about unknown names in the editor and might even do what is supposed to do 😉

mikepfly2
Frequent Visitor

Absolutely need this. I'm new to PowerApps and ran into this issue on day 2 and now my boss is suggesting Glide Apps, which I don't want. 

 

My use case:

Sharepoint list 1 with columns:

unit_number

drywall_start

drywall_finish

paint_start

paint_finish

flooring_start

flooring_finish

... for 30 more tasks (so 60 more columns)

 

Sharepoint list 2 with one column made up of task names:

drywall

paint

flooring

 

I want to create a gallery of the task names (using List 2) then use patch to update my table with one of two buttons:

 

mikepfly2_0-1625163078121.png

 

Started button:

Patch(MF_unit_tracker_job_C123,LookUp(MF_unit_tracker_job_C123,Title=var_unit_key),{Indirect(ThisItem.Title & "_start"):Now()})​

 

Finished button:

Patch(MF_unit_tracker_job_C123,LookUp(MF_unit_tracker_job_C123,Title=var_unit_key),{Indirect(ThisItem.Title & "_finish"):Now()})​

 

I would also use an indirect type of function for the label text and have another column in the Task list for a friendly name. 

 

Approaching 3 years on this request. Inserting an if switch for 66+ columns is not a viable solution. 

tgibso2
Frequent Visitor

I have a SharePoint List with 120 columns used to record periodic maintenance activities at various worksites.

The list is populated through a Form in an App.

 

Not all columns in the list apply to every site, so I have built a second list that references each question and shows true or false against each site. I want to use this second list to determine whether or not questions are visible for the selected worksite.

 

The easiest way to do this that I can come up with is to use an expression in the Visible field of each question such as LookUp(Reference_List, Site=myLocation, Parent.DataField)

In this case Parent.DataField would be the column title in both SharePoint Lists. 

 

This doesn't currently work unless I explicitly replace Parent.DataField with the column name, but if it did it would save a lot of time as I could just paste the same expression into each card rather than having to specify the column name each time.