Skip to main content

Notifications

Community site session details

Community site session details

Session Id : ZulCwDgDw4Kh97++uXYebf
Power Apps - Building Power Apps
Answered

Adding additional data to nested collection

Like (0) ShareShare
ReportReport
Posted on 11 Jun 2020 18:47:32 by

I have a simple setup but just can't get it to work. Understanding the logic behind nested collections is just a little too difficult. 

I have simplified my code below:

First I create the general collection with a nested collection under Item2:

 

 

ClearCollect(col_test1, {Item1: "Text", Item2: {Child1: "Random"}});

 

 

How do add (Collect) a new row to the nested collection under Item2?

I just cannot get it to work. 

I get Patch to work, changing "Random" to "Random_new".

 

 

Patch(col_test1,LookUp(col_test1,Item1="Text"),{Item2:{Child1:"Random_new"}})

 

 

But adding a new row to the nested collection is just impossible for me. Can anyone help me?

Thanks!

Categories:
  • Verified answer
    v-bofeng-msft Profile Picture
    on 12 Jun 2020 at 06:10:19
    Re: Adding additional data to nested collection

    Hi @Triplee23 :

    Do you want to add records to a subtable in the collection?

    My method is to use Split and concat to construct the table to update the data.

    The key is to construct a new table as the value to be updated.

    Case1:The value of Iterm2 is a single column table

    Ceate collection:

     

    ClearCollect(col_test1,{Item1: "Text", Item2: Table({Child1: "Random"})})

     

    Add Record:

     

    Patch(
     col_test1,
     LookUp(col_test1,Item1="Text"),
     {
     Item2: RenameColumns(
     Split(
     Concatenate(
     Concat(
     LookUp(
     col_test1,
     Item1 = "Text"
     ).Item2,
     Child1,
     "#"
     ),
     "#","Random_new"
     ),
     "#"
     ),
     "Result",
     "Child1"
     )
     }
    )

     

    1.JPG

    Case2:The value of Iterm2 is a multiple columns table

    Ceate collection:

     

    ClearCollect(col_test1, {Item1: "Text", Item2: Table({Child1: "Random"})})

     

     Add Record:

     

    Patch(
     col_test1,
     LookUp(
     col_test1,
     Item1 = "Text"
     ),
     {
     Item2: ShowColumns(
     AddColumns(
     Split(
     Concatenate(
     Concat(
     Concatenate(
     LookUp(
     col_test1,
     Item1 = "Text"
     ).Item2.Child1,
     "%%",
     LookUp(
     col_test1,
     Item1 = "Text"
     ).Item2.Child2,
     "%%",
     LookUp(
     col_test1,
     Item1 = "Text"
     ).Item2.Child3
     ),
     Result,
     "#"
     ),
     "#",
     "Random_new",
     "%%",
     "Random_new",
     "%%",
     "Random_new"
     ),
     "#"
     ),
     "Child1",
     First(
     Split(
     Result,
     "%%"
     )
     ).Result,
     "Child2",
     Last(
     FirstN(
     Split(
     Result,
     "%%"
     ),
     2
     )
     ).Result,
     "Child3",
     Last(
     FirstN(
     Split(
     Result,
     "%%"
     ),
     3
     )
     ).Result
     ),
     "Child1",
     "Child2",
     "Child3"
     )
     }
    )

     

    2.JPG

    Best Regards,

    Bof

     

  • Community Power Platform Member Profile Picture
    on 11 Jun 2020 at 19:52:20
    Re: Adding additional data to nested collection

    Thanks for the explanation, I got it to work. I understand that the principle here is that I create 2 collections and place one inside the other. 

     

    I am planning to use this collection (col_test1) in a nested Gallery, Gallery_Child (Item2: col_test2 collection) inside Gallery_Parent (col_test1 collection). With you solution, I would need as many child collections as records in col_test1.

     

    Keeping your first ClearCollect, is there no way to avoid your second piece of code, meaning adding a new record to Item2 without going through Patch(col_test2)? Can I not add a new record directly referring only to col_test1?

  • Community Power Platform Member Profile Picture
    on 11 Jun 2020 at 19:27:56
    Re: Adding additional data to nested collection

    The way you are doing it,  will always overwrite the Item2 because Item2 is not a collection or a table. It is record with one column. To add a new child to item 2 you can do the following.

    I did this on my end with 2 collections so you can add to them separately. 

    I added this line on the app OnStart property 

    ClearCollect(col_test2, {Child1: "Random"}); ClearCollect(col_test1, {Item1: "Text", Item2: col_test2});

    And this on a button which adds a new item

    Patch(col_test2, Defaults(col_test2), {Child1: "New Random"}); ClearCollect(col_test1, {Item1: "Text", Item2: col_test2});

     

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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Power Apps - Building Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 93 Most Valuable Professional

#2
MS.Ragavendar Profile Picture

MS.Ragavendar 60

#3
stampcoin Profile Picture

stampcoin 48

Overall leaderboard
Loading started