Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Building Power Apps
Suggested answer

Save Gallery in Sharepoint

(1) ShareShare
ReportReport
Posted on by 151
I would like to save my entire collection in a SharepointList. But I don't want to have to click on every single article for the patch formula, I really just want to click on a button and it then saves everything in a SharepointList. 
I've tried a bit to create a collection and then try to transfer it, but somehow it doesn't work. Is there a way?
Categories:
  • Kellboy2243 Profile Picture
    51 on at
    Save Gallery in Sharepoint

    Hi 

    To save your entire collection in a SharePoint list with a single button click in PowerApps, you can use the ForAll function combined with the Patch function. Here's a step-by-step guide:

    Step-by-Step Solution:

    1. Create the Collection:

      • If you haven't already created a collection that stores the data you want to save to SharePoint, you can create one using the ClearCollect function.
      • Example:
        ClearCollect(MyCollection, YourDataSource)
         
      • Replace YourDataSource with the actual data source you're pulling data from (e.g., another SharePoint list, SQL table, etc.).
    2. Patch the Collection to SharePoint:

      • Use the ForAll function to loop through each item in the collection and patch it to the SharePoint list.
      • Example:
        ForAll(
            MyCollection,
            Patch(
                YourSharePointList,
                Defaults(YourSharePointList),
                {
                    Column1: Value1,
                    Column2: Value2,
                    ...
                }
            )
        )
        
         
      • Replace YourSharePointList with the name of your SharePoint list.
      • Replace Column1, Column2, etc., with the actual column names in your SharePoint list.
      • Replace Value1, Value2, etc., with the corresponding values from your collection items (e.g., ThisRecord.ColumnName).

    Important Considerations:

    • Delegation: Ensure that the data source you are working with supports delegation if you're working with large datasets. Otherwise, PowerApps might only handle the first 500 or 2000 records, depending on your app's settings.
    • Performance: If your collection contains many items, this operation might take some time to complete, especially if the SharePoint list has complex fields or if the network is slow.

    Example Scenario:

    Let's say you have a collection called InvoiceItems with columns Product, Quantity, and Price. You want to save all items in this collection to a SharePoint list named Invoices.

    You would create the following OnSelect action for your button:

    ForAll(
        InvoiceItems,
        Patch(
            Invoices,
            Defaults(Invoices),
            {
                ProductName: ThisRecord.Product,
                Quantity: ThisRecord.Quantity,
                Price: ThisRecord.Price
            }
        )
    )
    

    Conclusion:

    This method allows you to save all items from a gallery or collection to a SharePoint list with a single button click, without having to manually patch each item individually.

    4o
  • Suggested answer
    RoyG Profile Picture
    16 Super User 2025 Season 1 on at
    Save Gallery in Sharepoint
    You can patch the entire collection in a single Patch() using the following:
    Patch(SP_List ; ForAll(ShowColumns(Gallery1.AllItems; ID); { ID: ID; Abschluss: "Ja" } ))
    This should work faster than Patch within ForAll.
    Hope this helps. 
  • rzuber Profile Picture
    545 Super User 2025 Season 1 on at
    Save Gallery in Sharepoint
    Something like this might work
    ForAll(
        Gallery1.AllItems As _article;
        With(
            {
                _record: If(
                    IsBlank(LookUp(SP_List; ID=_article.ID));
                    Defaults(SP_List);
                    LookUp(SP_List; ID=_article.ID)
                )
            };
            Patch(
                SP_List;
                _record;
                _article
            )
        )
    )
     
     
  • MiniMax92 Profile Picture
    151 on at
    Save Gallery in Sharepoint
    Ok, that almost worked. I now have the problem that it creates a new data set in SharePoint every time and does not update the existing one. This is my formula:
     
    ForAll(
        Gallery1.AllItems;
        Patch(
            SP_List ;
            Defaults(SP_List)
    
     ; { Abschluss: "Ja" } ))
     
  • Ram Prakash Profile Picture
    5,154 Super User 2025 Season 1 on at
    Save Gallery in Sharepoint
    Hi,
     
    There are 2 ways we can achieve this
     
    1. Send Values from Canvas App to Power Automate
     
    // Define the collection variable
    ClearCollect(GalleryItems, Gallery.AllItems);
    
    // Convert collection to JSON
    Set(jsonData, JSON(GalleryItems, JSONFormat.IncludeBinaryData));
    
    // Run the flow
    YourFlow.Run(jsonData);
     
    2. Use below code to save to SP
     
    ForAll(
        MyCollection,
        Patch(
            TEST, 
            Defaults(TEST),
            {
                Name: ThisRecord.Name,
                Title: ThisRecord.Title
            }
        )
    );
     
     
    Follow me for Move videos : https://www.youtube.com/@rampprakash3991
     
     
     
  • MiniMax92 Profile Picture
    151 on at
    Save Gallery in Sharepoint
    I've now tried something again and at least for the first time in Sharepoint, it works. But he doesn't do it for the others, even though "ForAll" is supposed to apply that to the gallery.
     
    ForAll( Gallery1.AllItems; Patch(SP_List;
    LookUp( Gallery1.AllItems; ID = ThisRecord.ID; ThisRecord )
    
     ; { Abschluss: "Ja" } ))
     
    Don't understand why it doesn't apply to every record in the gallery. 
  • MiniMax92 Profile Picture
    151 on at
    Save Gallery in Sharepoint
    I would like to add articles in my gallery to a SharePoint list at the click of a button. But all articles that are in the gallery. Not just the selected ones.
     
  • WarrenBelz Profile Picture
    146,653 Most Valuable Professional on at
    Save Gallery in Sharepoint
    Can you please tell me exactly what you are trying to do here. Do you want the entire collection to be sent to SharePoint as new records ? If so is every field in the collection also in the list with exactly the same name and data type ?
  • MiniMax92 Profile Picture
    151 on at
    Save Gallery in Sharepoint
    Oh my Bad.
    But it isn't still working.
    I Try it with this formular:
     
    Patch(Sharepointlist; Col_fin )
    The error Message: Invalid argument type (table). A record is expected at the moment.
  • WarrenBelz Profile Picture
    146,653 Most Valuable Professional on at
    Save Gallery in Sharepoint
    You are patching it to itself- you cannot do this - you need to Patch the collection

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,653 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 65,999 Most Valuable Professional

Leaderboard