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.
Solved! Go to Solution.
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!
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.
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*/
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.
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!