cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
JimSutt1
Frequent Visitor

Collection Patching: Patch with Defaults then Patch First?

I'm trying to use a single record collection for both inserts and updates, and I'm running into issues when I create a blank row in the collection and then try to Patch that row.  

 

First, I create a collection using the Defaults function so that I have a blank record with all the database table columns:

Spoiler
ClearCollect(collectTest, Defaults(<DB Table Name>));

Next, I have a gallery with Items = collectTest, and all of the columns of that collection are displayed as input strings.  The OnChange property of each input field has a similar notation:

Spoiler
Patch(collectTest, First(collectTest), {<column name>:  input.Text});

The patch is successful, but adds the data to a new blank row rather than patching the first row.  Am I using the First() function incorrectly?  I only want to patch that first record until patching the database with all the data entered.  

Note that I'm recording these changes as they are entered as I'm also using the same gallery for updates, which work fine with the same Patch and First functions above.  So it seems that having a blank row doesn't qualify using First.  Thoughts on how to get around this?

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
cwebb365
Super User
Super User

The blank row is your first use of the ClearCollect without passing a record it's just passing in blank. You need to either remove it, or not use it at all. Just use a single Patch(collectTest, Defaults(<DB Table Name>), {<column name>:  input.Text}); this should do the same thing, minus the extra blank record. 

View solution in original post

1 REPLY 1
cwebb365
Super User
Super User

The blank row is your first use of the ClearCollect without passing a record it's just passing in blank. You need to either remove it, or not use it at all. Just use a single Patch(collectTest, Defaults(<DB Table Name>), {<column name>:  input.Text}); this should do the same thing, minus the extra blank record. 

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Carousel_PP_768x460_Wave2 (1).png

2022 Release Wave 2 Plan

Power Platform release plan for the 2022 release wave 2 describes all new features releasing from October 2022 through March 2023.

365 EduCon 768x460.png

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Top Solution Authors
Users online (5,125)