web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Patch a collection of ...
Power Apps
Unanswered

Patch a collection of items to SharePoint List

(0) ShareShare
ReportReport
Posted on by 69

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.

Categories:
I have the same question (0)
  • Verified answer
    Shanescows Profile Picture
    2,218 Most Valuable Professional on at

    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. 🙂 

     

     

  • rorybi Profile Picture
    69 on at

    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

  • NPrice99 Profile Picture
    1,302 on at

    Hi Shane

     

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

     

    Regards

     

    Nigel

  • Shanescows Profile Picture
    2,218 Most Valuable Professional on at

    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? 

  • NPrice99 Profile Picture
    1,302 on at

    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

     

     

  • Rick72 Profile Picture
    385 on at

    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

  • NPrice99 Profile Picture
    1,302 on at

    Hi Shane

     

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

     

    regards

     

    Nigel

  • SergiP Profile Picture
    118 on at

    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?

     

  • SergiP Profile Picture
    118 on at

    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.

  • Community Power Platform Member Profile Picture
    on at

    Hello All,

     

    Facing an issue . i have written a code to patch the collection to sharepoint. but whenver i click the save button the data dosent seem to be visible in my sharepoint list even though my collection is having the required data.

     

    Steps i followed :-

    1. created a list called input in sharepoint and developed a form in powerapps. 

    2. after updating the form i saved it in a collection.

    3. Created a new list in sharepoint and made sure that the columns match in collection.

    4. Created a Button "Save" and wote a patch line  as 

     

    ForAll(Collection3, Patch(list, Defaults(list), {collection3column:sharepointcolumn,Title:Title})).

     

    errors: - 

     

    When testing the form, the toggle dosent appear for the save Button but it apprears to the record button. due to which i am not able to see any data in my sharepoint list. 

     

    P.S : - Record Button saves the collection from a form 

     

    Can you please help me out.

     

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 796 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 327 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard