cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
cseewald
Frequent Visitor

Patching collection to Sharepoint list

Hi

 

I have searched for an answer to this with no luck. Please see screenshots.  I have created a collection but keep getting the error attached when I try and patch ☹.

4 REPLIES 4
ANB
Resolver I
Resolver I

Hi @cseewald ,

Instead of using "Department: colOrderItems.Department"

 

Use this  "Department: colOrderItems[@Department]", It should be applicable to other fields too. Please check this Microsoft article which talk about Disambiguation operator.

 

I hope this helps.

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs.

Thanks,

ANB

 

 

RandyHayes
Super User
Super User

@cseewald 

To start, your formula has the ForAll backward. You are trying to use it like a ForLoop in some development language - which PowerApps is not.  ForAll is a function that returns a table of records based on your iteration table and record schema.

It is more efficient to use the function as intended and will provide better performance.

 

Please consider changing your Formula to the following:

Patch('Stationery orders',
    ForAll(
        colOrderItems,
        {Title: Title,
         Qty: Quantity,
         Teacher: User,
         Department: Department,
         Manager: Manager,
         ItemID: ProductID
        }
    )
)    

 

You would be better off by retaining column names in your app as they are in your datasource.  So your collect formula would be:

If(!LookUp(colOrderItems, ProductID = ThisItem.ID, true),
    Collect(colOrderItems,
        {ItemID: ThisItem.ID,
         Title: ThisItem.Title,
         Qty: Value(Self.Text),
         Department: cboDepartments.Selected.Name,
         Teacher: User().Email,
         Manager: lblLinemanager.Text
        }
    )
)

With the above, the names would match your column names (unless you have renamed them in your list - in which case, you need to match the original name).

Then, your Patch formula would simply be:

Patch('Stationery orders', colOrderItems)    

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Hi RandyHayes

 

Thanks for the quick response...

 

I modified the collect formula to match your suggestion and its good.

 

If(!LookUp(colOrderItems, ProductID = ThisItem.ID, true),

// if the product if not found, add a new product to the collection
Collect(
colOrderItems,
{
ItemID: ThisItem.ID,
Title: ThisItem.Title,
Qty: Value(txt_Number_1.Text),
Department: cboDepartments_1.Selected.Name,
Teacher: User().Email,
Manager: lblLinemanager.Text}

),

 

 

However Patch statement is saying it wants a record, not a table - any ideas?

cseewald_1-1658315330726.png

 

 

 

RandyHayes
Super User
Super User

@cseewald 

Yes, when you see that error message, that means something totally different!  It actually means that you have a column (or several) that do NOT match the proper column name, or that you are providing invalid data types to a column.

The name needs to be identical to the real column name in your list.  If you have renamed ANY column, then you need to use the original name as you cannot rename a column in SharePoint (only visually, not behind the scenes).

 

 

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Helpful resources

Announcements
Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Top Solution Authors
Top Kudoed Authors
Users online (1,476)