cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Advocate V
Advocate V

Patch a collection of items to SharePoint List

Hi All,

 

I'm struggling with this one.  I have a use case where I would like to be able to use my app to create offline stats for childrens football (mainly because it would take too long to interact with sharepoint and I might not even have good reception).

 

I have a collection that I am trying to post to sharepoint.  SpotsStats is my Sharepoint List.  cnStats is my collection.

 

 

SportStats.JPG

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

The following syntax works (although it is nonsense!)

ForAll(cnStats,
Patch(SportStats, Defaults(SportStats),
{Weather: "My Weather Test"}))

 

When this code runs I end up with 4 rows in sharepoint (corresponding to the fact I have 4 rows in my collection).

 

My real objective is to do something along the following lines (see below) but it's not working:-

 

ForAll(cnStats,
Patch(SportStats, Defaults(SportStats),
{ ActionIndex: cnStats.Index, Action: cnStats.Action, Half: cnStats.Half,Result: cnStats.Result,Weather: cnStats.Weather})

 

Even the following is invalid syntax

 

ForAll(cnStats, 
Patch(SportStats, Defaults(SportStats), 
{Result: cnStats.Result})

 

This would suggest that the problem is with the cnStats.Result.  I've tried wrapping this in a text function Text(cnStats.Result) but still no joy.

 

Any ideas what I'm missing as it's pretty frustrating.

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Super User
Super User

Re: Patch a collection of items to SharePoint List

ForAll is a pain in the butt (Technical term)

 

Are you just trying to add the 4 records to SharePoint? If that is the case drop all of this and just do Collect(SharePoint, Collection) You are done. 🙂 

 

 

Shane - Microsoft MVP, YouTube, and PowerApps Consulting for when you are in a bind to get this fixed quickly. And finally we now have PowerApps Training

View solution in original post

15 REPLIES 15
Highlighted
Super User
Super User

Re: Patch a collection of items to SharePoint List

ForAll is a pain in the butt (Technical term)

 

Are you just trying to add the 4 records to SharePoint? If that is the case drop all of this and just do Collect(SharePoint, Collection) You are done. 🙂 

 

 

Shane - Microsoft MVP, YouTube, and PowerApps Consulting for when you are in a bind to get this fixed quickly. And finally we now have PowerApps Training

View solution in original post

Highlighted
Advocate V
Advocate V

Re: Patch a collection of items to SharePoint List

Hi @Shanescows thanks so much.  This worked a treat.  You do need to ensure that you align the field names between sharepoint and powerapps, but it's not a problem.

 

Cheers

 

Rory

Highlighted
Post Prodigy
Post Prodigy

Re: Patch a collection of items to SharePoint List

Hi Shane

 

What about if I want to update a SharePointlist from a PowerApps Collection ?

 

Regards

 

Nigel

Highlighted
Super User
Super User

Re: Patch a collection of items to SharePoint List

Nigel can you give me more info on what you are trying to accomplish? Why put the updates in a collection instead of just updating SharePoint directly? 

Shane - Microsoft MVP, YouTube, and PowerApps Consulting for when you are in a bind to get this fixed quickly. And finally we now have PowerApps Training
Highlighted
Post Prodigy
Post Prodigy

Re: Patch a collection of items to SharePoint List

Hi Shane

 

I have two related sharepoint lists in a master / slave relationship.

 

I do not want to update the slave list until the master list gets updated in case the user decides to bail out of updating the master list.

 

So I dont want inconsistent lists where, for example, when creating a new pair of lists, the slave list gets created but the user then bails out of creating the master list and I am left with a slave list with no corresponding maste list.

 

I hope this helps.

 

Nigel

 

 

Highlighted
Impactful Individual
Impactful Individual

Re: Patch a collection of items to SharePoint List

Hi @NigelP,

 

SharePoint is not a transactional system. So basically what you want is not possible.

 

I also have a parent/child setup for one of my apps. Here I first create the item in the parent list and use the ID of this new Item as the connection between the parent and child (or children in my case). The child list thus has a column which contains the related parent ID.

 

A workaround could be a scheduled PowerShell script (PnP PowerShell) which checks to see if there are any inconsistancies (a parent without a child or the other way around though for me it would make more sence to create the parent item first).

 

Robot Happy Rick

Highlighted
Post Prodigy
Post Prodigy

Re: Patch a collection of items to SharePoint List

Hi Shane

 

performance and to stop the pesky blue wavy line as it is SharePoint.

 

regards

 

Nigel

Highlighted
Helper II
Helper II

Re: Patch a collection of items to SharePoint List

I tried what you suggest:   Collect(SharePoint, Collection) and I get an error: "Field required"

 

let me explain what I do:

I have a SP List called DataList that I want to clean and remove old records in order to keep it small...

so I collect the closed items:   Collect(CollectionDone, Filter(DataList, Done="YES"))

 

So far I have all the records I need to archive in my CollectionDone...

if I try to directly Collect(DataListArchived, CollectionDone)  I get an error 9 for many fields (ID, Author, Editor, ....  all the columns directly generated by the system...)

So I tried DopColumns to get rid of these, after cleaning the CollectionDone and having only the info I need then I try again to Collect(DataListArchived, CollectionDone)   then I get the error 2 "Field Requiered" on the Attachments column...

Patch(DataListArchived, Defaults(DataListArchived), CollectionDone)    doesn't work either since Patch needs a record and CollectionDone is a table of records...

 

so what I'm missing?

 

Highlighted
Helper II
Helper II

Re: Patch a collection of items to SharePoint List

Finally I found out!

instead of clearing the columns with DropColumns I had to clear the collection with ShowColumns so that it makes sure you only have the data columns you really need. Then Collect (Sharepoint, Collection) works like charm.

Helpful resources

Announcements
Check this Out

Helpful information

Featuring samples like Return to the Workplace and Emergency Response Applications

August 2020 Community Challenge: Can You Solve These?

August 2020 Community Challenge: Can You Solve These?

We're excited to announce our first cross-community 'Can You Solve These?' challenge!

secondImage

Return to Workplace

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

secondImage

Super Users Coming in August

We are excited for the next Super User season.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (5,960)