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

Patch records (for, while loop)

I'm creating an app where you select any day in a week and 7 records, one for each day in the week are created by patch. I live well copying the same script code 7 times to achieve this.

 

But, for each of these 7 days (tbLines) about 15 lines in a subtable (tbLineDetails) are also supposed to be created. I would normally have used a for each while loop function to do this, but it looks like those functions are missing or not needed in PowerApps. I guess the way around would be something with collections and ForAll, but can't see how.

 

 

Logic:

 

tbLines

Id

Date

 

tbLineDetails

Id

FKtbLinesID

 

Category

Value

 

CollCategory

 

Category

Value

 

varFirstdate   (a calculation makes sure picking the calendar selects first day of that week)

 

Idea is that when ou click the button, one record for each week should be created in tbLines. For each of the line records, all records in CollCategory should be copied to each day. CollCategory is a filtered table, so number of records and content may change.

 

Any ideas how to script this?

1 ACCEPTED SOLUTION

Accepted Solutions
Anonymous
Not applicable

Quite easy after sleeping on it, so to answer my own question:

 

A nested ForAll is all it takes. Something like:

 

ForAll 
     (CategoryColl,
          (ForAll
               (tbLinesColl,
                    (Patch(tbLineDetails,Defaults(tbLineDetails), {FKtbLinesID: ID}, {Category: Category}))
              )
          )
     )

Hope that makes sense!

View solution in original post

3 REPLIES 3
v-monli-msft
Community Support
Community Support

Hi @Anonymous,

 

Can you share some screenshots of the app you are trying to build  for better understanding? I couldn't fully understand what your requirement is. What is the data source you are using?

Do mask sensitive data before uploading.

 

Regards,

Mona

Community Support Team _ Mona Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Hi,

I haven't actually done any design yet, so this is more of a concept. See below for more details on data structure. The idea is that I want a script to patch 7 lines in tbLines (one for each day of the week). Then, for each day, patch the result of CategoryColl into tbLineDetails. Hope that makes sense.Capture.PNG

 

 

Regards,

Rol

Anonymous
Not applicable

Quite easy after sleeping on it, so to answer my own question:

 

A nested ForAll is all it takes. Something like:

 

ForAll 
     (CategoryColl,
          (ForAll
               (tbLinesColl,
                    (Patch(tbLineDetails,Defaults(tbLineDetails), {FKtbLinesID: ID}, {Category: Category}))
              )
          )
     )

Hope that makes sense!

Helpful resources

Announcements
Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Power Apps Ideas

Check out the New Ideas Site

We are excited to announce a new way to share your ideas for Power Apps!

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