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 / Add column while creat...
Power Apps
Answered

Add column while creating collection from gallery

(0) ShareShare
ReportReport
Posted on by 1,257 Super User 2024 Season 1

I create a simple collection on the check function of a checkbox on an item in the gallery

Collect(colmycollection,ThisItem)

 

I then use that collection to populate a second gallery.  

 

Gallery1 items come from a list datasource however there is an additional text box added into the gallery that isn't in the datasource and it's free text for the user.  Obviously when I create the collection above it doesn't pick this up? I know I need to maybe add a column to collect this text, but I haven't managed to figure out  how to do this.    

 

TIA

 

 

Categories:
I have the same question (0)
  • WiZey Profile Picture
    3,023 Moderator on at

    Hello @vffdd ,

     

    If I got this right :

     

    1. Gallery1 is linked to the datasource
    2. A checkbox add Gallery1.Item to a collection
    3. Gallery2 is linked to the collection
    4. There is a textinput in Gallery2
    5. You want to collect the textinput

     

    If you only need to add a column to your collection, you could use "AddColumns()".

     

    https://learn.microsoft.com/en-us/power-platform/power-fx/reference/function-table-shaping

     

    Otherwise, could you be a bit more explicit about your goal with the textinput? If you need to update the item with the value from the textinput, could you perhaps use "Patch()" in the "OnChange" of the textinput?

  • vffdd Profile Picture
    1,257 Super User 2024 Season 1 on at

    Thanks @WiZey 

     

    ok I was trying to keep the explanation simple but probably confused things.  So yes to your questions above but there are 2 ways I could approach this I believe and I'm not sure which is the best but either way I haven't figured it out and of course I've looked at the link you gave above plus numerous other posts and videos on adding columns, but they don't quite fit my scenario they don't show that I can see, how to create a collection from a gallery item and add a column at the same time.

     

    Yes I have 2 galleries a  I use the checked items in gallery1 (the collection) to fill gallery2 and I then patch those items back to a SP List. 

     

    However I need an extra text input filled in by the user.  This is NOT a field that is in the datasource which populates gallery1,  I can  create that text input at the on select of the check box stage when I'm creating the collection and then for gallery 2 just use thisitem.textfield which I think would be the cleanest.  Or I guess I could add the text box only to gallery2 and collect that data when I'm patching back.. but I feel the first option is cleanest.  Therefore I need to add a colum at the time of creating the collection.  

    Collect(colmycollection,ThisItem)

      hope that explains

    TIA

  • WiZey Profile Picture
    3,023 Moderator on at

    I think I have a clearer picture. If I'm not wrong, you want to add a new column to the item you're creating from gallery1 to gallery2. Something like this?

     

    Collect(
     collection, //Add new item to gallery2
     AddColumns( 
     ThisItem, //Get item columns and values
     'newColumn', //Add new column to record's structure
     'default text' //Default value to let user fill in, could be blank too
     )
    )

     

    By the way the code above doesn't work, we'll have to try something else.

     

    The code below should to the trick:

     

    Collect(
     collection, //Add new item to gallery2
     {
     Title: ThisItem.Title, //Column from gallery1
     Value: ThisItem.Value, //Column from gallery1
     ..., //Other columns from gallery1
     NewColumn: 'value' //New column for gallery2
     }
    )

     

     It may be a bit tedious if you want to use a lot of columns though. If you want to retrieve ALL columns at once, then try the following code:

     

    With(
     {
     _item:Table(ThisItem) //Create a table with a single record to use the item's structure
     };
     Collect(
     collection; //Add item to gallery2
     First(
     AddColumns(
     _item; //Based on the structure from the list
     "NewColumn"; //we create a new column
     "Value" //with the value we need
     )
     )
     )
    )

     

    Because "AddColumns()" requires a table as input and doesn't accept records, we can cheat a little by feeding it a table with a single record. "First()" retrieve this single record and then add the new column to the item created in the collection.

  • vffdd Profile Picture
    1,257 Super User 2024 Season 1 on at

    Thanks @WiZey  yes I had tried what you wrote in the first  code box as I thought it was a nice simple solution cos I wanted to avoid the middle option of adding the columns individually !  so I'll try the 3rd one and let  you know..:)

  • vffdd Profile Picture
    1,257 Super User 2024 Season 1 on at

    @WiZey  can you double check your code in the 3rd option as can't quite get it to work

  • Verified answer
    WiZey Profile Picture
    3,023 Moderator on at

    No issue on my side. I added the code in the "OnSelect" of a button in a gallery, it correctly creates a new record with the new column.

     

    A shorter version would be:

     

    Collect(
     collection;//Add item to gallery2
     First(
     AddColumns(
     Table(ThisItem);//Based on the structure from the list
     "NewColumn";//we create a new column
     "Value"//with the value we need
     )
     )
    )

     

    Could you describe the error you're getting here? 

  • vffdd Profile Picture
    1,257 Super User 2024 Season 1 on at

    I'm just using it exactly before I change the names to what I want them to be.  The error is covering the text but it's the same as yours apart from the collection name.

     

    This is a button in the gallery and the on select function

     

    vffdd_1-1669044749813.png

     

  • WiZey Profile Picture
    3,023 Moderator on at

    Is it perhaps a typo issue? Do you use « ; » or « , » to separate parameters?

  • vffdd Profile Picture
    1,257 Super User 2024 Season 1 on at

    I tried both actually.   You know what don't worry about it  I don't want to spend too much more time on this as I have to move on I'm going to look at doing it a different way !  Thanks so much for your help so far 

  • quincyt Profile Picture
    79 on at

    I had the exact same error as you had when testing it and it was because of the semicolon. When I changed it to below, it worked for me:

    Collect(
     collection,//Add item to gallery2
     First(
     AddColumns(
     Table(ThisItem),//Based on the structure from the list
     "NewColumn",//we create a new column
     "Value"//with the value we need
     )
     )
    )

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

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard