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 / 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:
I have the same question (0)
  • 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,616 Moderator 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,616 Moderator 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,616 Moderator 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

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 721 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 320 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard