cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Post Prodigy
Post Prodigy

Patch collection to collection

In my app I have a need to patch a collection with data from another collection.  

 

It sort of works, but I know I am missing something and so far have not been successful in figuring it out.

 

Scenario:

Choice is made in app and collect action populates the collection.   If a second choice is made the new data is patched to the collection that was just populated.  This isn't the typical repeating table scenario, however.

 

Multiple items are being populated into the collection each time.

 

  • Data Source:  SharePoint list
  • Collection: Market2
  • Collection: Market4
  • Dropdown Control with Regions

 

  • User selects region - Markets2 is populated with all the countries belonging to that region
  • User selects 2nd region - Markets 4 is populated with all the countries in that region

MarketsCollections.png

  • Markets4 is patched to Markets2, adding all the newly selected countries.

marketspatchformula.png

 

As you can see in the images below the patch is only patching one record in Markets4 to Markets2 and not all the fields, only the Country and Country Code.   Patch(Markets2, {Column3: Region}.... or Patch(Markets2, {Column3: Title}.... return the same results.   No errors either.

 

Markets4 Collection

markets4Collection.png

 

Markets2 collection after patch

markets2Afterpatch.png

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted

Hi @JR-BejeweledOne :

Do you want to add the records in Markets4 to Markets2?

Firstly,let me explain why you encounted this problem.

The key is that when you need to Modify or create a record in a data source, the second parameter of the Patch function is BaseRecord.

BaseRecord:The record to modify or create. If the record came from a data source, the record is found and modified. If the result of Defaults is used, a record is created.

Secondly,Please try this code:

 

ForAll(Marktes4,Patch(Markets2,Defaults(Markets2),{Column3:Region,Column2:Country,Title:CountryCode}))

 

 I think this link will help you a lot:

https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-patch#syntax

Best Regards,

Bof

View solution in original post

4 REPLIES 4
Highlighted
Helper II
Helper II
Highlighted

Thank you but no, I have the basics working correctly.   I believe my issue is something to do with the ForAll.    It correctly patches the first record of the Markets4 collection to the Markets2 collection.  It just doesn't patch the remaining records.

Highlighted

Hi @JR-BejeweledOne :

Do you want to add the records in Markets4 to Markets2?

Firstly,let me explain why you encounted this problem.

The key is that when you need to Modify or create a record in a data source, the second parameter of the Patch function is BaseRecord.

BaseRecord:The record to modify or create. If the record came from a data source, the record is found and modified. If the result of Defaults is used, a record is created.

Secondly,Please try this code:

 

ForAll(Marktes4,Patch(Markets2,Defaults(Markets2),{Column3:Region,Column2:Country,Title:CountryCode}))

 

 I think this link will help you a lot:

https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-patch#syntax

Best Regards,

Bof

View solution in original post

Highlighted

Thank you, That worked.   I was missing the 'Defaults (Markets2).

 

Is the 'Defaults(Name)' a specific requirement of the ForAll patch?   I don't have to use it when patching with thisitem.xxxx

 

 

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Community Highlights

Community Highlights

Check out the Power Platform Community Highlights

Top Solution Authors
Top Kudoed Authors
Users online (7,879)