cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

Collecting a variable number of items

I am trying to create a collection where it creates individual line items based on a qty that is variable. 
Example: A form is filled out with product specs and a qty is entered of 4. I have a button that would collect the data but create 4 entries into the collection. Is that possible?

Thank you. 

1 ACCEPTED SOLUTION

Accepted Solutions
Anonymous
Not applicable

I found this thread and used this method:
https://powerusers.microsoft.com/t5/Building-Power-Apps/Collect-item-depending-on-number-in-TextInpu...

On the OnVisible property of the screen or the OnStart property of the app, have a collection of numbers (until the max number a user can enter)

ClearCollect(NumberCollection,["1","2","3","4","5","6","7","8","9","10",...,"98","99","100",...])

Then on the OnSelect property of a button, have this to collect the item multiple times:

ForAll(FirstN(NumberCollection,Value(TextInput1.Text)), Collect(CollectionName, ThisItem))

Thanks for all the help and ideas!

View solution in original post

4 REPLIES 4
WarrenBelz
Super User
Super User

Hi @Anonymous ,

I will give you a "rough" way of doing it

If(
   qty>0,
   Collect(Your New Item code)
);
If(
   qty>1,
   Collect(Your New Item code)
);
If(
   qty>2,
   Collect(Your New Item code)
)

and so on. If you have small numbers, this would be the quickest way.

 

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.

v-bofeng-msft
Community Support
Community Support

Hi @Anonymous :

Do you want to add a specified number of records based on user needs?

My method is to use loops, because PowerApps does not support looping statements (except ForAll can be used to traverse the table), so here I use the Timer control.I've made a test for your reference:

1\Add a textInput control(TextInput3)

2\Add a timer control

Duration:

 

100 /*loop in 0.1s*/

 

OnSelect:

 

Set(var,0) /*var is my custom variable*/

 

OnTimerEnd:

 

Set(var,var+1);Collect(collection,{Title:1})/*Add a record(collection is my custom collection)*/
/*The event is executed once every loop*/

 

Repeat:

 

var<Value(TextInput3.Text)-1 /*When the condition is not satisfied, then jump out of the loop*/

 

 15.gif

Best Regards,

Bof

Thanks @v-bofeng-msft  - that is the "not rough" way on larger numbers.

@Anonymous  either will work - depends on the number you have to do.

Anonymous
Not applicable

I found this thread and used this method:
https://powerusers.microsoft.com/t5/Building-Power-Apps/Collect-item-depending-on-number-in-TextInpu...

On the OnVisible property of the screen or the OnStart property of the app, have a collection of numbers (until the max number a user can enter)

ClearCollect(NumberCollection,["1","2","3","4","5","6","7","8","9","10",...,"98","99","100",...])

Then on the OnSelect property of a button, have this to collect the item multiple times:

ForAll(FirstN(NumberCollection,Value(TextInput1.Text)), Collect(CollectionName, ThisItem))

Thanks for all the help and ideas!

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (3,131)