cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
mr-dang
Community Champion
Community Champion

Patch a Collection

The release notes for 2.0.531 indicates an improvement to the Patch function that I'm excited about: 

 

 

7. Update multiple records at once by using the Patch function.

Create or update more than one record at a time by specifying a table of base records and 
a table of change records as arguments for the Patch function.

 

I think this is what I've been waiting for, but I'm not sure how to use it. 

 

Can I save a Collection with identical fields back to the datasource? For instance, can I Patch the rows in Collection1 into DataSource1 if they have identical columns? I've been trying:

 

Patch(DataSource1,Collection1)

 

but that does not result in any new rows written. What am I doing wrong?

 

 

EDIT: could it be that the default fields (Title, CreatedOnDateTime, etc.) are blank in the Collection, so it cannot be Patched with those blank?

Microsoft Employee
@8bitclassroom
39 REPLIES 39
hpkeong
Community Champion
Community Champion

Hi

 

Thanks a lot.

Looks like, as you have posted, there are several ways of PATCH syntax.

1. Patch(DS, Collection) - DONE!

2. Patch(DS, BaseRecordsTable, use ForALL) - DONE!

 

For No. 2, I had tried to understand ForALL and found it needs some effort to understand the requirements beneath and good to be combined with Patch. Think simple..this is what I capture from your sharing.

 

I try to post here of what I had accomplished.

So, it is clear that:

- Use Collect a batch of New Record and Patch in Batch

- Use Filtering (with Dropdown, ListBox,..) and use Gallery + TextInput to list WISH-List for Editing (Modifying) and PATCH (Replace) in Batch.

This greatly improve the:

- Saving speed (as all data are cloud-linked)

- Editing speed (batch edit and batch saving).

 

Ocne again, my appreciation.

I shall try other options as suggested and I wish my examle posted here can be helpful to others as well as PG in amending the existing Learn Tutorial to give others a clearer and Practical way of using Patch + ForAll for BATCH DATA processing.

 

Batch Editing of Records and ReplaceBatch Editing of Records and Replace

 

hpkeong

I am glad this helped. As you hinted -- think functionally instead of imperatively. PowerApps is really optimized for the former, very much like Excel is. In the process, you will likely find that functional solutions tend to be more concise.

Radu Gruian [MSFT] ** PowerApps Staff

Hi,

 

I am trying to use this code

 

Button2.OnSelect = Patch(TableBook, SourceBook, ForAll(Gallery1.AllItems, { Book: TextInput1.Text, Author: TextInput2.Text, Language: TextInput3.Text }))

 

But I am getting the error "Invalid Argument type (Table). Expecting a record value instead". And If I am trying to add collection directly then also I am not able to add new records to the List(datasource).

 

Thanks

Hi @KrunalPatel

Try this:

 

Button2.OnSelect = Patch(TableBook, SourceBook, ShowColumns(AddColumns(Gallery1.AllItems,  "Book", TextInput1.Text, "Author", TextInput2.Text, "Language", TextInput3.Text), "Book", "Author", "Language"))

 

Hi @Meneghino,

 

I am using the exact code as specified but I am getting the error

 

This is my expression

 

Patch(Answer, Defaults(Answer), ShowColumns(AddColumns(BrowseGallery1_1.AllItems,  "Title", Heading1_1.Text, "SelectedChoice", TextBox4.Text), "Title", "SelectedChoice"))

 

But I am getting error

 

Thanks

 

 

Hi @KrunalPatel, let me test this.

What is your data source? (i.e. CDS, SQL Server, SharePoint list...)

Hi @Meneghino,

 

My datasource is SharePoint list.

What are the column types? Are they all text or do you also have a choice or lookup column?

If so, please also have a look at this:

https://powerusers.microsoft.com/t5/PowerApps-Forum/Solved-patching-to-SharePoint-choice-and-lookup-...

Hi @Meneghino,

 

My column type is single line of text for both fields. No Lookup or choice field.

This worked for me when creating new records in Answer, a SharePoint list:

 

Collect(Answer, ShowColumns(AddColumns(BrowseGallery1_1.AllItems,  "Title", Heading1_1.Text, "SelectedChoice", TextBox4.Text), "Title", "SelectedChoice"))

Please let me know.

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

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Are Your Ready?

Test your skills now with the Cloud Skill Challenge.

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Top Solution Authors
Top Kudoed Authors
Users online (86,890)