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/...


pagonza
Community Support
Community Support

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

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

365 EduCon 768x460.png

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Users online (4,912)