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?
Solved! Go to Solution.
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!
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
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.
Regards,
Rol
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!