cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Smilee279
Helper I
Helper I

Gathering all items in a collection column and save to SP List

Hello!

 

I setup a shopping cart in my app, and have it saving to a collection (collection1).  On submit of a button, I want it to take all the Items in the cart and the Qty and patch that to the same cell on the ID of the SP List.  TLDR:  I used Shane Young's video for the shopping cart code:
https://www.youtube.com/watch?v=Ztn39KuOW0g&list=PLCGGtLsUjhm2bonhBZuEhZU72QkFjOpc6&index=126

 

That being said, I have my cart, saved to collection1, and it's displaying at checkout the items in that collection properly--however, when I tell it to patch the items and quantity, it only shows the last item in the collection (patched to my SPList).  I have the below:

 

*varselectedItem is the variable I used to pass through data on previous screen's forms.  

OnSelect of my submit button:

ForAll(collection1, Patch(SPList1, LookUp(SPList1, ID = varselectedItem.ID),{'Items Ordered': Item & QTY}));

 

Smilee279_0-1620321718719.pngSmilee279_1-1620321799424.png

 

I just can't get it to save all of the items ordered, it's just showing the last item & quantity ordered.

6 REPLIES 6
RandyHayes
Super User III
Super User III

@Smilee279 

You are trying to write a list of records into one record.  It appears from the picture that the column is a text column.  You you trying to have all of these items from the Gallery in one column in that record?

Can you explain more about what you are expecting in the list, as again, you are only specifying ONE record to patch.

 

EDIT: Also, if you have the ID in the Collection (by the way, you don't need a collection for this process you are doing), then your formula should be:

   Patch(SPlist1, ForAll(collection, {ID: ID, 'Items Ordered': Item & Qty})

_____________________________________________________________________________________
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.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes
zaphod88
Responsive Resident
Responsive Resident

Try

ForAll(collection1, Patch(SPList1, LookUp(SPList1, ID = collection1[@ID]),{'Items Ordered': Item & QTY});
Smilee279
Helper I
Helper I

@RandyHayes @zaphod88 

I'm sorry--I meant to put this information in my original post--which I will update.  

 

collection1 is pulling data from a different SPList (SPList2), hence the need to patch it to the master list (SPList1).  I'm using collection1 as the Items: in a gallery (which is displaying correctly per my screenshot). 

 

I'm trying to list all of the collection1.Item(s) into the one column/line.  Using my screenshot as an example, I'm trying to get it to show "Lunch - Hot buffet with lunch" 3, "Breakfast- continental" 3 into the single line under Items Ordered in my SPList (SPList1).  

 

 

RandyHayes
Super User III
Super User III

@Smilee279 

You can cut down on some of the overhead and extra work by eliminating the extra collections.

Your Gallery will have all the information you need to perform the patching.

But, as long as your collection has the record ID in it from your list, then the formula I mentioned would do the trick.

   Patch(SPlist1, ForAll(collection, {ID: ID, 'Items Ordered': Item & Qty})

 

_____________________________________________________________________________________
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.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes
Smilee279
Helper I
Helper I

@RandyHayes 
Since my collection is from a different SPList, it won't have the record ID for the master list in it.  collection1 is from SPList2, and I'm trying to patch the Item data from collection1 to SPList1.  The only way I've come close to getting it to work is using the code in my original post but it's not putting all of the data in it (just some of it).

ForAll(collection1, Patch(SPList1, LookUp(SPList1, ID= varselectedItem.ID),{'Items Ordered': Item & QTY}))

 

RandyHayes
Super User III
Super User III

@Smilee279 

Yes, your formula is backward, but beside that, how are you defining/collecting the collections?  They should have the ID in them for the record you want to update.

Your collection1 is the items of your Gallery.  I assume the collection1 is based on the list that you show in your picture...is that not the case?  Knowing the collections and the formulas you use to collect would assist.

I guess I am not getting why you have the two collections based on two lists.

And still in your formula, you are looking up the same record for all iterations and patching that one record...you will only ever have the last patch in it.

varSelectedItem is coming from a prior screen - it is only going to be one record.  So what is varSelectedItem all about?  

My assumption is that it is the master record from one of the lists and that you are trying to update child records in another list where they are related to the master.

 

Please correct where I am wrong and provide some of the details requested above.

 

_____________________________________________________________________________________
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.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Power Apps June 2021

June Power Apps Community Call

Did you miss the call? Check out the recording here!

Top Solution Authors
Top Kudoed Authors
Users online (18,646)