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

Adding a column to an existing collection

I already created a collection on a separate page with the navigation pointed to the page in question. I need to add three new columns to the Collection before I patch it to Sharepoint. 

 

Collect(WCDCOrder, AddColumns(Table('WCDC Branch #'), "Branch #", 'WCDC Branch #'.Text)

 

The issue I'm seeing from this formula is "Cannot use a non-record value in this context. 

 

I need to add three columns "Branch #", "Shipping Address", "Additional Comments". Help is greatly appreciated. 

 

11.PNG

9 REPLIES 9
RandyHayes
Super User
Super User

@BKICK 

Is WDC Branch # your existing collection?

If so, consider changing your formula to this:

Collect(WCDCOrder, AddColumns('WCDC Branch #', "Branch #", 'WCDC Branch #'.Text)

In other words, drop the Table function as that will produce the error you are seeing.

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!

@RandyHayes 

 

Thank you for your reply. The existing collection is WCDCOrder. 'WCDC Branch #' is the text input field I'm trying to add to the collection as a column.

 

I just tried this one and it says unexpected characters

 

Collect(WCDCOrder, AddColumns(WCDCOrder, "Branch #", 'WCDC Branch #'.Text)

 

@BKICK 

So, you're not trying to add a column as much as you are trying to add the data to a record??

If 'WCDC Branch #' is your control, then are you trying to add a column with a name of the value in that textbox control?  Or are you trying to add the value in the textinput control as a value to a record in the collection?

 

You will definitely end up with issues trying to collect the same collection like that as well.  You'll most likely see errors indicating that the column already exists.  Consider another collection, or just using the result of the AddColumns in an Items property and skip the collection (if it works for the rest of your needs).

_____________________________________________________________________________________
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!

@RandyHayes 

 

Randy, If I create a second collection is there a way to merge both collections together and then patch to a sharepoint list? 

@BKICK 

That's not an easy quick answer...it depends!  A lot on what you are actually trying to achieve.  If you are pushing the collection back to your datasource, then they need to have the same field signatures.  If not, then you can use other techniques to make it happen...so again, it really depends.

 

Keep in mind though that functions like AddColumns and other collection/table based formulas will return the entire modified collection (a copy).

 

So, I'm not sure this directly answers your question, but perhaps if not, supply some more detail on what you are actually trying to achieve.   From your original post, I assume you have these three columns already in your SharePoint data source and that you're not trying to Add the columns in PowerApps.

And, I would also add that, if your goal is to "build up" an item that you are then planning to submit back to SharePoint, that using a collection to achieve that is probably not the best route - using a record is all you would need OR even better, skip the record, skip the collection and just put your logic in the submit that you need.  Keep in mind that you can access all the controls of all the screens from any place in the app - so, you do not need to "collect" or "store" the values in controls as you go from screen to screen.

_____________________________________________________________________________________
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!
v-siky-msft
Community Support
Community Support

Hi @BKICK ,

 

What is the logic of the code?  - Collect(WCDCOrder, AddColumns(WCDCOrder, "Branch #", 'WCDC Branch #'.Text)

As @RandyHayes said, AddColumns function returns a shaped table/collection, so we always use ClearCollection to save the shaped table into a new Collection. it is not supported to save to the previous collection.

BTW, A bracket “)” is missing at the end of the formula, so the correct syntax of code should be:

Collect(WCDCOrder_1, AddColumns(WCDCOrder, "Branch #", 'WCDC Branch #'.Text))

 

It will generate a new Collection named WCDCOrder_1, with a "Branch #" column fill with WCDC Branch #' Text.

I am not sure if this meets your requirments, since the WCDC Branch #' Text is filled into each row.

If this doesn't work for your case, please share more details about your requirement.

Sik

 

@v-siky-msft@RandyHayes 

 

Thank you very much for the responses and your patience. I'm very inexperienced and have been self teaching myself through youtube videos. With that said here is what I have and what I'm trying to do. I created a purchasing app for my organization for internal requests. I used excel as my data source and I want to capture whatever is requested in sharepoint. From there build various flows as notifications. 

 

This is my catalog of items and the logic behind the "Add To Cart" Button. So far so good.

 

1.PNG

 

As items are added to the shopping cart they are added to a collection which is then displayed in the checkout screen. 

 

2.PNG

 

I can send the collection to Sharepoint and direct the data to the various columns in sharepoint. The challenge I'm facing is getting the three text inputs into Sharepoint as these aren't apart of the collection. My first thought was to add them to the collection as new columns but I couldn't get that far. My second thought was to create a new collection of these three fields and then merge it with the other collection. 

 

Any advice is greatly appreciated. 

 

Thank you. 

@BKICK 

I'm not seeing that you necessarily need to add these to a collection.  If I am understanding correctly, the three input boxes you have are relevant to the entire order.  

 

Let's start with - what is your patch formula looking like?  You can simply add the three column values in that patch rather than try to get them into a collection.

_____________________________________________________________________________________
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 @BKICK ,

 

What is the formula you save the Collection to Sharepoint list?

Could you please share the SharePoint list construct?

Do you want three texts to appear repeatedly on each line of the order, as follows?

Product

Branch #

Shipping Address

Additional Comments

Gloves

A

B

C

Battery

A

B

C

If so, I think you can try this.

 

Collect(WCDCOrder_1, AddColumns(WCDCOrder, "Branch #", 'WCDC Branch #'.Text, "Shipping Address", TextInput2.Text, "Additional Comments", TextInput3.Text))

 

Then, save WCDCOrder_1 collection to the SharePoint list as before.
If this doesn't make sense, please share more information.
Sik

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,857)