cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ruchiga
Level: Powered On

Repeating Controls

I have about 50 controls. I don't want to copy and paste and change the number like the below code.

ClearCollect(BACollect,
{BU: DDBU.Selected.Value,Country:ddCountry.Selected.Value,Hours: Value(txtHour.Text)},
{BU: DDBU_1.Selected.Value,Country:ddCountry_1.Selected.Value,Hours: Value(txtHour_1.Text)},
{BU: DDBU_2.Selected.Value,Country:ddCountry_2.Selected.Value,Hours: Value(txtHour_2.Text)},
...

);

 

Is there any easy code for this like for loop? 

For counter = 1 to 50

{BU: DDBU_.counter.Selected.Value,Country:ddCountry_counter.Selected.Value,Hours: Value(txtHour_counter.Text)},

 

or something like that?

 

 

7 REPLIES 7
Super User
Super User

Re: Repeating Controls

@ruchiga 

Unfortunately, PowerApps cannot dynamically reference control names as you have mentioned.  There are no shortcuts here.

 

Are you familiar with MS Excel?  I think the closest analogy I can give to what you are trying to do is the INDIRECT function in Excel which allows the user to construct cell references using variables.  I would suggest voting for the Idea below if this is a feature you would like to see in PowerApps.

 

Link to Idea:

https://powerusers.microsoft.com/t5/PowerApps-Ideas/INDIRECT-References/idi-p/772

Community Support Team
Community Support Team

Re: Repeating Controls

Hi @ruchiga ,

Do you add 50 controls (Dropdown box, Text Box, ...etc) to collect data in your app?

 

Based on the needs that you mentioned, I think it is not necessary to 50 controls in your app, instead, a Gallery control could achieve your needs.

You could add a Gallery control in your app, then add your three data enter controls (DDBU, ddCountry and txtHour) within this Gallery.

 

I have made a test on my side, please consider take a try with the following workaround:

1. Add a Gallery control (Gallery1), set the Items property to following:

[1,2,3,4,5,6,7,8,9,10,11,....,45,46,47,48,49,50]

2. Add two Dropdown box (DDBU and ddCountry) and a Text Input box (txtHour) within above Gallery.

3. Set the OnSelect property of the "Button" to following (modify your formula as below😞

Clear(BACollect);
ForAll(
       Gallery1.AllItems,
       Collect(
               BACollect,
               {
                 BU: DDBU.Selected.Value,
                 Country: ddCountry.Selected.Value,
                 Hours: txtHour.Text
               }
       )
)

 

Please check and see if the following video resources would help in your scenario:

https://www.youtube.com/watch?v=xgznk4XlPCo

https://www.youtube.com/watch?v=DylxsXIUyDc

https://www.youtube.com/watch?v=HUX_0AA4-Hs

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
ruchiga
Level: Powered On

Re: Repeating Controls

Thanks for your explanation. I completed my app using repeating controls like what I said in my original description. I just wanted to know if there is any other option so I don't have to add 50 controls in the future. I am using the SharePoint list as a data source...

 

ForAll(BACollect,Patch('SPList',
Defaults('SPList'),
{
BU: DDBU.Selected.Value,
Country: ddCountry.Selected.Value,
Hours: txtHour.Text
}
))

 

How will this work with your approach for using SharePoint?

 

Thank you for your help!

 

Community Support Team
Community Support Team

Re: Repeating Controls

Hi @ruchiga ,

Yes, the solution I provided above could achieve your needs with SP List as data source.

 

If you use SP List as data source in your app, please consider modify above "Submit" formula as below:

Set the OnSelect property of the "Submit" button to following (modify your formula as below : )

ForAll(
       Gallery1.AllItems,
       Patch(              /* <-- Save data into your SP list directly, rather than save into a collection firstly */
               'SPList',
                Defaults('SPList'),
               {
                 BU: DDBU.Selected.Value,
                 Country: ddCountry.Selected.Value,
                 Hours: txtHour.Text
               }
       )
)

 

Please consider take a try with above solution, then check if the issue is solved.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
ruchiga
Level: Powered On

Re: Repeating Controls

I am using two lists - subcategory and SPlist. I am trying to pull the number of items from the subcategory instead of using [1,2,3,4,5,6,7,8,9,10,11,....,45,46,47,48,49,50] in the Items property of the Gallery control. Let's say, the subcategory list has 25, 30, 35 etc. How can I do that? Thanks for your help...

ruchiga
Level: Powered On

Re: Repeating Controls

 
ruchiga
Level: Powered On

Re: Repeating Controls

@v-xida-msft  Please see my previous post. Is it possible?

Helpful resources

Announcements
Better Together’ Contest Finalists Announced!

'Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

thirdimage

Power Apps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Join THE global Microsoft Power Platform event series

Attend for two days of expert-led learning and innovation on topics like AI and Analytics, powered by Dynamic Communities

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

thirdimage

Microsoft Business Applications Virtual Launch

Join us for the Microsoft Business Applications Virtual Launch Event on Thursday, April 2, 2020, at 8:00 AM PST.

thirdimage

Community Summit North America

Innovate, Collaborate, Grow - The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Top Kudoed Authors
Users online (10,631)