cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Super User
Super User

Create a Dynamic Collection Based on User Input?

Hello,

I don't think I've done this before (or at least I can't remember nor find a community post about it). Maybe you can help?

Scenario:

- User inputs a number into a Textbox control

- I need to create a Collection of items equal to this number

Example:

- User enters "5" into the Textbox

- Create a Collection with 5 records (a template of sorts that accepts user input)

- If user enters "8", create a Collection with 8 records, etc.

 

Has anyone a solution for this?

 

Thank you!

2 ACCEPTED SOLUTIONS

Accepted Solutions
Super User III
Super User III

Hi @seadude ,

Use FirstN around the details

ClearCollect(
   colMyCollectioon,
   FirstN(
      Filter(
         Mylist,
         MyField=Whatever
      ),
      Value(MyNumberTextBox).Text
   )
)

 

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 Up.

 

View solution in original post

@seadude 

Sequence() could give the dynamic use case you are seeking? @mdevaney has a blog case on it's use here.

 

Using it for your solution could look like:

ClearCollect(
  ColDynamicWeights,
    AddColumns(Sequence(Value(TextInput1.Text)),
       "label", "Test"&Value,
       "weights", Blank()
)

 

Just another option really and not to take anything away from @WarrenBelz's solution.

 

Note: my code is missing an ending ')' but I'm unable to edit as I'm using my iPad.

 

View solution in original post

6 REPLIES 6
Super User III
Super User III

Hi @seadude ,

Use FirstN around the details

ClearCollect(
   colMyCollectioon,
   FirstN(
      Filter(
         Mylist,
         MyField=Whatever
      ),
      Value(MyNumberTextBox).Text
   )
)

 

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 Up.

 

View solution in original post

@WarrenBelz ! Nice solution, thank you.

Here's how I adapted it for my use case:

- Use case:

  - Users will receive shipments of 1-~10 units

  - As part of an intake process, they must weigh each unit

- Since each unit is unique, I substituted the Filter statement with a static table with GUID()'s

  - The Table statement works if your app only requires a small number of dynamic elements (<~20-30)

  - There is a way to use a "numbers table" and ForAll to get more records

    - I don't think PowerApps has true dynamic capabilities here, you'll always need a reference table to iterate/loop through

ClearCollect(
   colDynamicWeights,
   FirstN(
      Table(
          { id: GUID(), label: "test1", weight: ""},
          { id: GUID(), label: "test2", weight: ""},
          { id: GUID(), label: "test3", weight: ""},
          { id: GUID(), label: "test4", weight: ""},
          { id: GUID(), label: "test5", weight: ""},
          { id: GUID(), label: "test6", weight: ""},
          { id: GUID(), label: "test7", weight: ""},
          { id: GUID(), label: "test8", weight: ""},
          { id: GUID(), label: "test9", weight: ""},
          { id: GUID(), label: "test10", weight: ""}
      ),
      Value(TextInput1.Text)
   )
)

Results: A dynamic Collection based on user input of number of records! (Thanks @WarrenBelz !)

Peek 2020-09-05 09-18.gif

Hope this helps others too!

 

@seadude 

Sequence() could give the dynamic use case you are seeking? @mdevaney has a blog case on it's use here.

 

Using it for your solution could look like:

ClearCollect(
  ColDynamicWeights,
    AddColumns(Sequence(Value(TextInput1.Text)),
       "label", "Test"&Value,
       "weights", Blank()
)

 

Just another option really and not to take anything away from @WarrenBelz's solution.

 

Note: my code is missing an ending ')' but I'm unable to edit as I'm using my iPad.

 

View solution in original post

Wow... ok @Eelman and @mdevaney Sequence() is quite the statement! I was unaware of it before you mentioned it here! Thank you! I believe this does solve for the "true dynamic" piece of the puzzle.

To sum it up:

- If a dynamic collection of a known size is required, use a "numbers table" or CountRows/Filter() the known data source

- If a dynamic collection based on user input is required, use Sequence() and the users input

PowerApps Community... !!

giphy.gif

Just a follow up note here...

Sequence() has powered up the latest app I'm building! It allows me to create data capture templates based on user input, something I've ALWAYS struggled to do in PowerApps.

A-woo., A-hoo.!

Hi @seadude ,

Another use on this post (do this x number of times).

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Community Highlights

Community Highlights

Check out the Power Platform Community Highlights

Top Solution Authors
Top Kudoed Authors
Users online (12,005)