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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Help with Patch and Fo...
Power Apps
Answered

Help with Patch and ForAll

(1) ShareShare
ReportReport
Posted on by 550

Hello - I've read a number of posts on this topic (and think my code is close), but I still am getting errors while attempting to patch a collection to a Sharepoint list. I am not patching to all the Sharepoint columns - just those specified using the ShowColumns function. 

 

Sp list name: 'InventoryOrders'

collection name: colMyCart

 

Code:

 

UpdateContext({showLoading: true});
// insert a new row for each product ordered into the SharePoint list
Patch(
 'InventoryOrders',
 ForAll(
 colMyCart,
 Defaults('InventoryOrders')
 ),
 ShowColumns(
 colMyCart,
 "ProductId",
 "ProductName",
 "Model",
 "Color",
 "Quantity",
 "PricePer",
 "UserName",
 "UserID",
 "UserEmail"
 )
);
UpdateContext({showLoading: false});
Navigate(PlaceOrderScreen);

 

The error:

kky1_0-1693949473060.png

 

And the Sharepoint list columns ( I should note the actual names of the columns are field_1, field_2, etc, but with the setting to use display names in columns, the app seems to be recognizing their actual names):

kky1_0-1693949685998.png

 

 

It appears it is expecting a record rather than a table eventhough I have the ForAll function included.

 

Thank you to anyone who can assist.

Kendra

@kky1 

Categories:
  • poweractivate Profile Picture
    11,078 Most Valuable Professional on at

    Try this:

    UpdateContext({varShowLoading: true});
    
    // Insert a new row for each product ordered into the SharePoint list
    Patch(
     'InventoryOrders',
     ForAll(
     colMyCart,
     Defaults('InventoryOrders')
     ),
     ForAll(
     colMyCart,
     {
     ProductId: ProductId,
     ProductName: ProductName,
     Model: Model,
     Color: Color,
     Quantity: Quantity,
     PricePer: PricePer,
     UserName: UserName,
     UserID: UserID,
     UserEmail: UserEmail
     }
     )
    );
    
    UpdateContext({varShowLoading: false});
    Navigate(PlaceOrderScreen, ScreenTransition.None);
    

    See if it helps @kky1 

  • kky1 Profile Picture
    550 on at

    Thank you for responding so quickly! I pasted in the revised code but am still getting an error:

    kky1_0-1693950369889.png

     

  • SebS Profile Picture
    4,869 Super User 2026 Season 2 on at

    @kky1 

     

    If You attepting to do Batch Patch the ForAll should not be required try below 🙂

     

    UpdateContext({showLoading: true});
    // insert a new row for each product ordered into the SharePoint list
    Patch(
     'InventoryOrders',
     ShowColumns(
     colMyCart,
     "ProductId",
     "ProductName",
     "Model",
     "Color",
     "Quantity",
     "PricePer",
     "UserName",
     "UserID",
     "UserEmail"
     )
    );
    UpdateContext({showLoading: false});
    Navigate(PlaceOrderScreen);

     

  • kky1 Profile Picture
    550 on at

    for reference in case I missed something in my collection, here is the table of values:

    kky1_1-1693950472430.png

     

  • kky1 Profile Picture
    550 on at

    Thank you@SebS and @poweractivate . Still running into an error though even without the ForAll:

    kky1_0-1693950682493.png

     

  • SebS Profile Picture
    4,869 Super User 2026 Season 2 on at

    @kky1 

     

    I bet it's due to the Color Column remove Color for moment and try then it's classed as complex type and you should not patch it that way

  • SebS Profile Picture
    4,869 Super User 2026 Season 2 on at

    @poweractivate 

     

    If you use @poweractivate  code with that small change I think it should go 🙂

     

    UpdateContext({varShowLoading: true});
    
    // Insert a new row for each product ordered into the SharePoint list
    Patch(
     'InventoryOrders',
     ForAll(
     colMyCart,
     Defaults('InventoryOrders')
     ),
     ForAll(
     colMyCart,
     {
     ProductId: ProductId,
     ProductName: ProductName,
     Model: Model,
     Color: {Value: Color},
     Quantity: Quantity,
     PricePer: PricePer,
     UserName: UserName,
     UserID: UserID,
     UserEmail: UserEmail
     }
     )
    );
    
    UpdateContext({varShowLoading: false});
    Navigate(PlaceOrderScreen, ScreenTransition.None);
    

     

  • poweractivate Profile Picture
    11,078 Most Valuable Professional on at

    @kky1 

    I really hate to use ForAll outside Patch in this way but to just have a starting point, do it like this first and see if it works to get it working fast:

    UpdateContext({varShowLoading: true});
    
    // Go through each item in colMyCart and patch it to InventoryOrders
    ForAll(
     colMyCart,
     Patch(
     'InventoryOrders',
     Defaults('InventoryOrders'),
     {
     ProductId: ProductId,
     ProductName: ProductName,
     Model: Model,
     Color: Color,
     Quantity: Quantity,
     PricePer: PricePer,
     UserName: UserName,
     UserID: UserID,
     UserEmail: UserEmail
     }
     )
    );
    
    UpdateContext({varShowLoading: false});
    Navigate(PlaceOrderScreen, ScreenTransition.None);
    


    If it worked let me know and I try to tell you how to do it the right way like you were doing with Patch outside ForAll.

  • kky1 Profile Picture
    550 on at

    Thanks again @SebS - I removed Color from the Patch statement but it still is throwing an error. Not sure if any of the other columns would be complex. 

  • poweractivate Profile Picture
    11,078 Most Valuable Professional on at

    @kky1 Temporarily try the inefficient way (I hate it, but it may help debug for now), with ForAll outside Patch like I gave it. Try removing the Color, etc as well. See if you can get a version working at all. Then I might try give you the optimized version Patch outside ForAll.

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 354 Super User 2026 Season 2

#2
M Bilal Khan Profile Picture

M Bilal Khan 320

#3
Mohsin Ali Profile Picture

Mohsin Ali 246

Last 30 days Overall leaderboard