web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Invalid Argument Type ...
Power Apps
Answered

Invalid Argument Type Error on Button to Patch Collection

(0) ShareShare
ReportReport
Posted on by 45

I have built an editable table displaying customers in the manner described by @Reza in one of his Youtube videos. I am trying to use a button to patch additions or changes to that collection to a customer table called Custs. The collection is call colCustUpdates.

 

As instructed by Reza, I have added a hidden button to the gallery with the OnSelect property set as shown below. The purpose is to check if a collection is in the Cust table. If it is present, the collection should update the table. Otherwise, the collection should be added to the table. The unique field created by Power Apps in the Cust table is also called Cust.

 

If(
ThisItem.Cust in colCustUpdates.Cust,
Update(
colCustUpdates,
LookUp(
colCustUpdates,
Cust=ThisItem.Cust
),
{
Cusname: Cusname.Value,
SCS_ID: SCS_ID.Selected.Value,
Active: Active.Selected.Value,
Auto_ID: Auto_ID.Value,
Shortname: Shortname.Value,
Region: Region.Selected.Value,
SOM: SOM.Value,
Cust: ThisItem.Cust
}
),
Collect(
colCustUpdates,
{
Cusname: Cusname.Value,
SCS_ID: SCS_ID.Selected.Value,
Active: Active.Selected.Value,
Auto_ID: Auto_ID.Value,
Shortname: Shortname.Value,
Region: Region.Selected.Value,
SOM: SOM.Value,
Cust: ThisItem.Cust
}
)
)

 

The button to save the collection has the following OnSelect property.

 

Patch(
Custs,
colCustUpdates
);
Clear(colCustUpdates);

 

The button has the error "Invalid Argument Type (Table). Expecting a Record value instead."

 

I've been trying for hours to figure out where the problem is. I believe it might be related to the Active field which is a Yes/No type. But, that's just a guess. Very open to suggestions.

Categories:
I have the same question (0)
  • Nick_F Profile Picture
    45 on at

    Some additional info:

    • I have verified all field names are spelled correctly
    • When I check the collection, I see all field values are correct

    So, it appears the issue is with the Patch command. 

  • Verified answer
    CarlosFigueira Profile Picture
    on at

    The Patch function requires three arguments to update records in a data source: the data source itself (Custs, in your case), the record to be updated (or a table of records), and the updates to be made. The overload with 2 parameters is used to merge records, which is not what you need.

    In your case, you can use the ForAll function to iterate through the collection, and patch the items to the data source. The example below is a general case that should work whether the items are being inserted or updated, but you can simplify it if you know that it will be all inserts (or all updates):

    ForAll(
     colCustUpdates As c,
     With(
     { toUpdate: LookUp(Custs, Cust = c.Cust) },
     Patch(Custs, Coalesce(toUpdate, Defaults(Custs)), c)
     )
    )

    If you know that all of the items in the collection will be inserted, the expression can be simplified: 

    ForAll(colCustUpdates, Patch(Custs, Defaults(Custs), ThisRecord))

    Similar with the case where you know that all the items in the collection will be updated:

    ForAll(colCustUpdates As c, Patch(Custs, LookUp(Custs, Cust = c.Cust), c))

    Hope this helps!

  • Nick_F Profile Picture
    45 on at

    Thank you, Carlos! All of your options appear to resolve the invalid argument type error.

     

    I am now getting a strange error: "The column 'Active' does not exist. The column with the most similar name is 'Active'."

     

    Active is identified as "Active: Active.Selected.Value". Is that appropriate for a Yes/No toggle column?

     

    Nick

  • calerof Profile Picture
    255 on at

    Hello @Nick_F ,

    The difference between your solution and Reza's is that the first collection he was doing was in a Gallery with the data source, with the Checkbox control under the On Check property with the following code:

    Collect(colUpdates, ThisItem)

    What this does is critical for the procedure explained by him. It creates the collection with the data source's metadata.

    In your case where is your table located? SharePoint, Dataverse, SQL? Let's assume it's on SharePoint.

    When you use Collect in your code (below) to create a new record in your table, Power Apps doesn't know what's that table's metadata, i.e. columns, column types, etc. 

    If(
     ThisItem.Cust in colCustUpdates.Cust,
     Update(
     colCustUpdates,
     LookUp(
     colCustUpdates,
     Cust=ThisItem.Cust
     ),
     {
     Cusname: Cusname.Value,
     SCS_ID: SCS_ID.Selected.Value,
     Active: Active.Selected.Value,
     Auto_ID: Auto_ID.Value,
     Shortname: Shortname.Value,
     Region: Region.Selected.Value,
     SOM: SOM.Value,
     Cust: ThisItem.Cust
     }
     ),
     Collect(
     colCustUpdates, {
     Cusname: Cusname.Value,
     SCS_ID: SCS_ID.Selected.Value,
     Active: Active.Selected.Value,
     Auto_ID: Auto_ID.Value,
     Shortname: Shortname.Value,
     Region: Region.Selected.Value,
     SOM: SOM.Value,
     Cust: ThisItem.Cust
     }
     )
    )

    You can create a temporal collection based on your data source (first record) to create the metadata, then clear the temporal collection and then copying it to your collection with this code:

    ClearCollect(colTemp, First(Custs));
    Clear(colTemp);
    Collect(ColCustUpdates, colTemp);

    This way you'll have your metadata in the collection colCustUpdates and it will be blank. Then you can use Collect to save to your collection the new data.

    The final trick you're missing from Reza is that when you want to create a new record, you have to drop your table's unique identifier column, e.g. ID in the case of SharePoint, and passing the information to a new collection, like this:

    ClearCollect(
     colToPatch,
     DroppColumns(
     colCustUpdate,
     "ID",
     )
    )

    Now Power Apps knows that this collection is to create a new record, and you can save to your data source with Patch:

    Patch(Custs, colToPatch)

    Hope it helps.

    Regards,

    Fernando

     

    If this helped please give it a thumbs up. Even if your post is already solved it could benefit others.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 739 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard