web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / How to loop (for all) ...
Power Apps
Unanswered

How to loop (for all) and submit (submit form)

(0) ShareShare
ReportReport
Posted on by

Hi,

 

Idea:

User provides a start date and a period (number of months). For each month, a record should be added to an SP list. I.e. start date = 1/1/2022; period = 3, I wish 3 records, namely for the following dates:

1) 1/1/2022 ...

2) 1/2/2022 ...

3) 1/3/2022 ...

 

I created a ClearCollect  (ClearCollect(Loop, {Ind:0}, {Ind:1}, ...) in the OnStart of the App. Subsequently, on the OnSelect in the submit button I wrote: 

 

 

 

Set(i, 0);
ForAll(
 Filter(
 Loop, 
 Ind <= Max(period), 
 Ind >= i
 ),
 monthYear.SelectedDate = DateAdd(startDate.SelectedDate, Ind, Months);
 SubmitForm(Form1)
)

 

 

 

 

This does not do anything (I also do not receive an error). 

 

Hope someone can be of help 🙂

Categories:
I have the same question (0)
  • WarrenBelz Profile Picture
    153,034 Most Valuable Professional on at

    Hi @Anonymous ,

    SubmitForm() will not do anything here - you need to Patch in this structure

    With(
     {
     wMonth:
     DateAdd(
     startDate.SelectedDate, 
     Ind, 
     Month
     )
     },
     Patch(
     YourListName,
     ForAll(
     Filter(
     Loop, 
     Ind <= Max(period) &&
     Ind >= i &&
     monthYear.SelectedDate = wMonth
     } As aPatch,
     {
     Field1: aPatch.Field1,
     Field2: aPatch.Field2,
     Field13 aPatch.Field3,
     . . . . . . 
     }
     )
     )
    )

     

    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.

    Visit my blog Practical Power Apps

  • Community Power Platform Member Profile Picture
    on at

    rix0_0-1668692547267.png

    If(
     IsBlank(ComboBox1.Selected), 
     Notify("Please Select a vendor"),
     Set(i, 0)
     //Notify(Max(DataCardValue13));
     With(
     {
     wMonth:
     DateAdd(
     DataCardValue12.SelectedDate,
     Ind,
     Months
     )
     },
     Patch(
     'Vendor Rating',
     ForAll(
     Filter(
     Loop, 
     Ind <= Max(DataCardValue13),
     Ind >= i),
     DataCardValue11.SelectedDate = wMonth
     } As aPatch,
     {
     Title: aPatch.DataCardValue15.Selected.VendorID_Name,
     StartDate: aPatch.DataCardValue12.SelectedDate,
     ...
     }
     )
     )
     )
    )

    First of all, thanks for the reply!

    Sadly, this did not work for me.

  • WarrenBelz Profile Picture
    153,034 Most Valuable Professional on at

    @Anonymous ,

    I was assuming Ind is the number of months to be added - is it something else ? Also you are missing a semi-colon after Set(i,0)

  • Community Power Platform Member Profile Picture
    on at

    I made some changes trying to get rid of the errors: 

    If(
     IsBlank(ComboBox1.Selected), 
     Notify("Please Select a vendor"),
     Collect(Records,
     ForAll(
     Filter(
     Loop, 
     Ind <= Max(DataCardValue13),
     DataCardValue11.SelectedDate = DateAdd(DataCardValue12.SelectedDate, Ind, Months)),
     {
     Title: DataCardValue15.Text,
     StartDate: DataCardValue12.SelectedDate,
     MonthYear: DataCardValue11.SelectedDate
     }
     )
     )
    );
    Patch(
     'Vendor Rating',
     Records
    )
    
    

    however now it does not fill the sharepoint list (also I am not sure whether the Collection even gets filled this way)

  • Community Power Platform Member Profile Picture
    on at

    The following seems to work for me,

    If(
     IsBlank(ComboBox1.Selected), 
     Notify("Please Select a vendor"),
     ForAll(
     Filter(
     Loop, 
     Ind <= Max(DataCardValue13)),
     Patch(
     'Vendor Rating',
     {
     Title: DataCardValue15.Text,
     StartDate: DataCardValue12.SelectedDate,
     MonthYear: DateAdd(DataCardValue12.SelectedDate, Ind, Months)
     }
     )
     )
    )

    Thanks for your help @WarrenBelz ! 

  • Verified answer
    WarrenBelz Profile Picture
    153,034 Most Valuable Professional on at

    @Anonymous ,

    You have your ForAll backwards - it will work that way, but with significant performance penalties. Rather than "loop" individual data source writes, ForAll constructs a Table that can be written in one action

    If(
     IsBlank(ComboBox1.Selected), 
     Notify("Please Select a vendor"),
     Patch(
     'Vendor Rating',
     ForAll(
     Filter(
     Loop, 
     Ind <= Max(DataCardValue13)
     ),
     {
     Title: DataCardValue15.Text,
     StartDate: DataCardValue12.SelectedDate,
     MonthYear: DateAdd(DataCardValue12.SelectedDate, Ind, Months)
     }
     )
     )
    )

     

    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.

    Visit my blog Practical Power Apps

  • YapaYapa Profile Picture
    125 on at

    Hello @WarrenBelz ,

    can you help me with similar issue?
    context below

    I created an app monitoring time duration for specific activities (by pushing 2 buttons Start and End) as visible from screenshot below. However, when the data are registered in the sharepoint list I have all the names of the individuals attending the session into one cell. Is there a way to create an entry for each one of the partecipants with the same data ( activity + duration)? 

    Fedegallo_0-1681207345660.png

     

     

     


    from what I have read the Forall function could help me achive that results but I dont know how to implement it with names of people ( person 1, person 2 and so on). Please find below screenshot of formula on Start button ( similar to the End one)

     

    Fedegallo_1-1681207358839.png

     

    Set(varNewItem, Patch('Coaching Tracker', Defaults('Coaching Tracker'), {'Created by': User().Email, 'Analyst''s EID': DataCardValue12.Text, 'Activity Performed': DataCardValue13.Selected, 'Code Used': DataCardValue14.Selected, 'Start Time': Now(), 'Session Active': true}));

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard