cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
jonathanO
Level: Powered On

Unable to remove column from collection - ClearCollect from a list box control adding extra column

I have a list box that contains vehicles.  The app will allow users to determine which vehicles were damaged in an accident.  The listbox will show as list of VIN numbers and user can select one or more vehicles.  

 

When the user presses save button, the app needs to update the SQL table table column AccidentID for each vehicle.  The AccidentID variable is already populated by the time this process takes place.

 

After trying many things, I thought @mr-dang's solution in this post would be best:

 

https://powerusers.microsoft.com/t5/General-Discussion/Patch-a-Collection/td-p/9329/page/3

 

Since I do not need to worry about creating records, only updating, I modified his solution to remove the part of the dorumla that creates a record if it doesn't already exist in the SQL table.

However, the issue I am running into is that when I ClearCollect() from the ListBox control, I have all of the expected columns from the SQL table (the items of the listbox control are from a SQL data source).  However, there is one extra column called "Value". 

I suspect that because of this, the Patch fails since the columns are not the same between the datasource and the collection.  In fact, a red squiggle shows under the Patch formula and ther error says "The specified column 'Value' not found".

I thought I could just remove the column, however, when I try to use DropColumns(VehicleDamages,"Value") I get an error that the column "Value" does not exist.  Yet, if I go to View > Collections > VehicleDamages, I clearly see a "Value" column.

 

So it seems that Patch() sees the Value column and I get an error, but DropColumns() does not see the column.

Any idea on how to either remove this column or how to update a column in SQL table for the records selected in a List Box?

 

Example:

 

1. Here is result of ClearCollect(VehicleDamages, VehiclesListBox.SelectedItems )  The ListBox items are from SQL table.  There is not a Value column in the SQL table

PatchIssue1.PNG

 

 

 

2. Here is the error if I try to drop the column:

PatchIssue2.PNG

 

 

3. Here is the formula and error from the Patch() function (formula adapted from mr-dang post):

 

Formula:

ForAll(RenameColumns(VehicleDamages,"ClaimVehicleID","CID"),
Patch('SQLTable',First(Filter('SQLTable',ClaimVehicleID=CID)),
First(Filter(VehicleDamages,ClaimVehicleID=CID))
)
)

Error:

InkedPatchIssue3_LI.jpg

1 ACCEPTED SOLUTION

Accepted Solutions
Power Apps Staff CarlosFigueira
Power Apps Staff

Re: Unable to remove column from collection - ClearCollect from a list box control adding extra colu

The Value is a column that comes from the ListBox selection - in addition to the other columns from the data source you're getting it. I don't know why you cannot drop that column - it's likely a bug, which I'll file with the team to fix.

 

As a workaround, you can select all other columns in the data source (using the ShowColumns function) and explicitly select the columns that exist on the database table:

ClearCollect(
    VehicleDamages,
    ShowColumns(
        VehiclesListBox.SelectedItems,
        "AuctionProceeds",
        "ClaimID",
        "ClaimVehicleID",
        "Color",
        "EstimatedVehicleDamage",
        "FeesCharged",
        ...
    )
)

With this you should be able to patch from the items in the collection.

View solution in original post

7 REPLIES 7
Community Support Team
Community Support Team

Re: Unable to remove column from collection - ClearCollect from a list box control adding extra colu

Hi @jonathanO,

 

How did you create this Value column? From SQL server data? What if you try to change to other columns in the collection to have a test? Will the same error occur on other columns or just this one?

 

Regards,

Mona

Community Support Team _ Mona Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Re: Unable to remove column from collection - ClearCollect from a list box control adding extra colu

Hi @jonathanO,

Have you already tried to adress the column 'value' by its original name from the database?

Power Apps Staff CarlosFigueira
Power Apps Staff

Re: Unable to remove column from collection - ClearCollect from a list box control adding extra colu

The Value is a column that comes from the ListBox selection - in addition to the other columns from the data source you're getting it. I don't know why you cannot drop that column - it's likely a bug, which I'll file with the team to fix.

 

As a workaround, you can select all other columns in the data source (using the ShowColumns function) and explicitly select the columns that exist on the database table:

ClearCollect(
    VehicleDamages,
    ShowColumns(
        VehiclesListBox.SelectedItems,
        "AuctionProceeds",
        "ClaimID",
        "ClaimVehicleID",
        "Color",
        "EstimatedVehicleDamage",
        "FeesCharged",
        ...
    )
)

With this you should be able to patch from the items in the collection.

View solution in original post

jonathanO
Level: Powered On

Re: Unable to remove column from collection - ClearCollect from a list box control adding extra colu

This worked, thank you @CarlosFigueira

daveone
Level: Powered On

Re: Unable to remove column from collection - ClearCollect from a list box control adding extra colu

Is there any solution on this problem since the DoropColumns command still doesn't work;

 

ClearCollect(DataTmp, DataFiltered);
DropColumns(DataTmp,"CODICE")

 

after then the collection DataTmp still have the column "CODICE"... why?

 

 

Power Apps Staff CarlosFigueira
Power Apps Staff

Re: Unable to remove column from collection - ClearCollect from a list box control adding extra colu

The DropColumns function doesn't change the table that is passed to it; instead it returns a table without that column. Take a look at the documentation for that function for more details.

For example, if you want DataTmp to have all columns in the DataFiltered collection except "CODICE", then you can use the following expression:

ClearCollect(DataTmp, DropColumns(DataFiltered,"CODICE"))
daveone
Level: Powered On

Re: Unable to remove column from collection - ClearCollect from a list box control adding extra colu

Yes, it works correctly as you suggested. Thanks.

Helpful resources

Announcements
New Ranks and Rank Icons in April

'New Ranks and Rank Icons in April

Read the announcement for more information!

Better Together’ Contest Finalists Announced!

'Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

thirdimage

Community Summit North America

Innovate, Collaborate, Grow - The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Top Kudoed Authors
Users online (4,537)