cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Jesper
Regular Visitor

Patch - Referance a column name via a variable

Hi,

 

I am trying to patch just the fields of a single colum, or a whole colum, to a datasource. The colum name can be anyone of 25 different names. I have tried to find a way to update the whole colum in one move, but i cant find a away that wil let me change the datasource when working with whole colums. I am using colums to sort the 500 records in the tables differently for each user.

 

So i am looking at a way to referance a colum name via a variable: I would like to be able to define the colum name via the 'ActiveSortTarget' but i cant get it to work.

 

Collect(UpdateChangesTemp,UpdateChanges);

ForAll(UpdateChanges, 
    Patch(If(LookUp(Hotel,NavnID = SelectHotel1.Selected.NavnID,Land = "France"),
          If(Slider1.Value = 1,'Vareliste Bar FR','Vareliste Koekken FR'),
          If(Slider1.Value= 1,'Vareliste Bar oe','Vareliste Koekken oe')),
    First(UpdateChangesTemp).RecordId,
    {ActiveSortTarget: Value(First(UpdateChangesTemp).ActiveSort)});
    Remove(UpdateChangesTemp,First(UpdateChangesTemp)));

Clear(UpdateChanges);

I can accomplish the task by wrapping it in a big Switch(), but was hoping for a simpler way.

 

Thanks in advance

 

1 ACCEPTED SOLUTION

Accepted Solutions
CarlosFigueira
Power Apps
Power Apps

Unfortunately this is not possible in PowerApps today - the name of the column used in patch requests cannot come from variables. You can consider creating a new feature request in the PowerApps Ideas board for this.

 

Regarding the Switch option, where you mentioned that you can "wrap it in a big switch" - that's currently the best way to do it, where you would have the switch call in the 'update' parameter of the Patch call.

 

View solution in original post

7 REPLIES 7
CarlosFigueira
Power Apps
Power Apps

Unfortunately this is not possible in PowerApps today - the name of the column used in patch requests cannot come from variables. You can consider creating a new feature request in the PowerApps Ideas board for this.

 

Regarding the Switch option, where you mentioned that you can "wrap it in a big switch" - that's currently the best way to do it, where you would have the switch call in the 'update' parameter of the Patch call.

 

View solution in original post

Okay, Thanks for the help 🙂

Anonymous
Not applicable

Hi, @CarlosFigueira any update on the "column referencing"? Is it still not possible to refer to column via variable name till now (July 5th, 2018)?

 

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

 

Patch(dbo_Condoc_Nesta, LookUp(dbo_Condoc_Nesta, ProductCode=Dropdown5.Selected.Value), {
Condoc_DataField_8 : TextInput2.Text
})

 

Thank you in advance. 

This is still not supported; I believe you can use some sort of If function implement it, but you'll need to list all possible columns, something along the lines of the expression below, as suggested by the OP in this thread.

Patch(
    dbo_Condoc_Nesta,
    LookUp(dbo_Condoc_Nesta, ProductCode = Dropdown5.Selected.Value),
    Switch(
        Dropdown5.Selected.Value,
        "Condoc_DataField_8",
            { Condoc_DataField_8: TextInput2.Text },
        "Condoc_DataField_7",
            { Condoc_DataField_7: TextInput2.Text },
        "Condoc_DataField_6",
            { Condoc_DataField_6: TextInput2.Text }))

Please consider voting up for an existing idea on the ideas board, or creating one if it doesn't exist.

Anonymous
Not applicable

Thank you for your help. But in my case, the number of columns to be updated is not fixed so that I may not be able to use the "Switch" function.

Anw, thanks again for the update. 🙂

Anonymous
Not applicable

Has there been any change to the use of Variables on selecting Columns on Patch function. This seems to be a major limitation if you want the user to select a Name (Row) and Column(Date) in order to update a specific attribute. I have tried referencing the DatePicker control in Patch but that does not work. So not sure how to get around giving the user the option to select and Name and Date to update a record. Seems this should be a basic feature...

just faced a similar need

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

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.

Top Solution Authors
Top Kudoed Authors
Users online (3,910)