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

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
roli_
Level: Powered On

Re: Patch records (for, while loop)

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
Community Support Team
Community Support Team

Re: Patch records (for, while loop)

Hi @roli_,

 

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.
roli_
Level: Powered On

Re: Patch records (for, while loop)

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

roli_
Level: Powered On

Re: Patch records (for, while loop)

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

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

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

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors (Last 30 Days)
Users online (3,778)