cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
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
Super User
Super User

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

16 REPLIES 16
Super User
Super User

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

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

Hi Shane

 

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

 

Regards

 

Nigel

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

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

 

 

Impactful Individual
Impactful Individual

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

Hi Shane

 

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

 

regards

 

Nigel

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?

 

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
New Badges

New Solution Badges!

Check out our new profile badges recognizing authored solutions!

New Power Super Users

Congratulations!

We are excited to announce the Power Apps Super Users!

Power Apps Community Call

Power Apps Community Call: February

Did you miss the call? Check out the Power Apps Community Call here.

Microsoft Ignite

Microsoft Ignite

Join digitally, March 2–4, 2021 to explore new tech that's ready to implement. Experience the keynote in mixed reality through AltspaceVR!

Top Solution Authors
Top Kudoed Authors
Users online (44,338)