cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
lgpower
Helper II
Helper II

ForAll Patch Multiple Tables for Multiple users

Hi all, 

I built an hour registration app with three entities in CDS which look more or less like this: 

1.
Name: TimeEntries (multiple records per employee per week)
Scheme: Week, Project, Employee, WeekStart, Mon, Tue, Wed, Thurs, Fri, Sa, Sun
ForAll & Patch Logic: 
Forall(gallery.AllItems,
IfIsBlank(TimeEntriesID; //If record is new 
Patch(TimeEntries;
Defaults(TimeEntries);
{...}
)
;// Else Update existing record 
Patch(TimeEntries;
{TimeEntriesID:TimeEntriesID};
{...}
)

2.
Name: TimeEntryPerDay/Employee (multiple records per employee per day) 
Scheme: Date (weekStart+x), Project, Employee, Hours, ReftoTimeEntries
ForAll & Patch logic: Here I have 7  Forall/Patch(Defaults(TimeEntryPerDay({...})) statements each patching a record for 1 day of the week (weekStart+x)... I also patch along the reference to the specific TimeEntries week record in CDS so that updates to the Hour/Project field can be done using a calculated reference field. 

3.
Name: TimeEntryRollup (one record per employee per week) 
Scheme: Week Employee TotalHours
Patch logic: Separate patch statement updating the Total hours an employee has worked in one week


So this all works, probably could do it more efficient here and there but OK. 

Now I want to add functionality where users can enter hours for their team at the same time. I would supply them with a list control where they can select for whom in their team they wish to enter times. 

In my set-up this would require me to create an additional record per user in all three tables where only the username is different. So if three users are selected, three records are created with the same project/hour values etc but different user. If one just one, etc... 

I am kind of stuck how to manage this efficiently in the patch logic. Would it be possible in the same statement? Any suggestions? 

Thanks in advance

1 ACCEPTED SOLUTION

Accepted Solutions
lgpower
Helper II
Helper II

Solved

Using logic described in below post I created an selectedUser collection and crossjoined that with the input records

 https://powerusers.microsoft.com/t5/Building-Power-Apps/Cross-join-or-Cartesian-Join-of-collections/...


View solution in original post

2 REPLIES 2
lgpower
Helper II
Helper II

Solved

Using logic described in below post I created an selectedUser collection and crossjoined that with the input records

 https://powerusers.microsoft.com/t5/Building-Power-Apps/Cross-join-or-Cartesian-Join-of-collections/...


View solution in original post

pagonza
Community Support
Community Support

Thank you for the information @lgpower ! Really can help others

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors
Users online (1,429)