I have been wracking my head trying to figure out the logic behind patching a record for each day between two dates. Essentially I'm trying to get this to automatically create a new record for each day starting with a StartDate and creating the last record for the EndDate. It checks to see if there is already a record created for that date, with the selected department. If it is found, it will update the record if its not found it will create the record.
When I do the simple Patch everything works, so I can reasonably assume that my issue is with the Date Range / Sequence. I just for the life of me can not figure out the logic in Powerapps to pull this off.
What I currently have is below. Thank you in advance if anyone has any pointers!
With(
{
startDate: StartDate.SelectedDate,
endDate: EndDate.SelectedDate
},
ClearCollect(
dateRange,
AddColumns(
Sequence(If(IsBlank(EndDate.SelectedDate), 1, DateDiff(startDate, endDate, TimeUnit.Days) + 1, 0, 1)),'DateCol',DateAdd(startDate, Value, TimeUnit.Days)
)
)
);
ForAll(
dateRange,
//Working Below
If(
IsBlank(LookUp(Sched_Tbls, Sched_Date = sDate_var && Sched_Dept = DepartmentSelect.Selected.Dept_Name)),
Patch(
Sched_Tbls,
Defaults(Sched_Tbls),
{Sched_Dept_Lookup: DepartmentSelect.Selected},
{Sched_Dept: DepartmentSelect.Selected.Dept_Name},
{Sched_S_Date: StartDate.SelectedDate},
{Sched_E_Date: EndDate.SelectedDate},
{Sched_Date: DateCol},
{Sched_P_Contact_Lookup: PrimeContactLookup.Selected},
{Sched_S_Contact_Lookup: SecondContactLookup.Selected},
{Sched_Notes: SchedNotes.Value}
),
Patch(
Sched_Tbls,
LookUp(Sched_Tbls, Sched_Date = sDate_var && Sched_Dept = DepartmentSelect.Selected.Dept_Name),
{Sched_Dept_Lookup: DepartmentSelect.Selected},
{Sched_Dept: DepartmentSelect.Selected.Dept_Name},
{Sched_S_Date: StartDate.SelectedDate},
{Sched_E_Date: EndDate.SelectedDate},
{Sched_Date: DateCol},
{Sched_P_Contact_Lookup: PrimeContactLookup.Selected},
{Sched_S_Contact_Lookup: SecondContactLookup.Selected},
{Sched_Notes: SchedNotes.Value}
)
)
)