cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Frequent Visitor

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
Highlighted
Super User III
Super User III

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

Highlighted
Community Support
Community Support

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.
Highlighted
Frequent Visitor

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!

 

Highlighted
Community Support
Community Support

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.
Highlighted
Frequent Visitor

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

Highlighted
Frequent Visitor

Re: Repeating Controls

 
Highlighted
Frequent Visitor

Re: Repeating Controls

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

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Find your favorite faces from the community presenting at the Power Platform Community Conference!

Watch Now

Experience what’s next for Power Apps

See the latest Power Apps innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (5,752)