cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
seadude
Memorable Member
Memorable Member

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
WarrenBelz
Super User
Super User

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
WarrenBelz
Super User
Super User

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

seadude
Memorable Member
Memorable Member

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

seadude
Memorable Member
Memorable Member

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
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Users online (2,273)