
Announcements
To be honest, this is an absurd scenario which I hope someone will be able to help me.
In short, my Patch formula failed to create the Parent record, whereas the child record continued to be created but associated itself to an incorrect Parent.
My Patch() formula creates a Reservation record (Parent), and Reservation Detail record (Child).
- 1 day reservation = 1x Reservation , 1x Reservation Detail
- 3 days reservation = 1x Reservation , 3x Reservation Detail
Below is a scenario to replicate the issue.
1) 1x Reservation and 3x Reservation Detail created for 25-Jan to 27-Jan (3 days) for Desk 7
2) Reservation Details cancelled for 25-Jan only
3) User creates new Reservation for 25-Jan of same Desk 7
4) An error occurred during Reservation creation
Network error when using Patch function: The requested operation is invalid.
Console Log:
5) New Reservation (parent) failed to create.
New Reservation Detail (child) is created, but associated to previous Reservation (parent) above, which is incorrect.
I understand this is a ridiculous scenario, but I sincerely hope someone will be able to point me in the right direction to why this is happening. If more information is required, I will be glad to provide them.
Below is my Patch() function, which I am unable to identify any potential cause of it.
//Create new 'Reservation' (parent) record
If(
BookingType_Self_Cb.Checked,
ClearCollect(
ReservationRecord,
Patch(
Reservations,
Defaults(Reservations),
{
'Start Date': FromDate_Dp.Value,
'End Date': ToDate_Dp.Value,
'Reserved For': 'Reserved For (Reservations)'.Employee,
Facility: Building_Ddl.Selected,
Area: Area_Ddl.Selected,
'Employee Name': Self_Section_EmployeeName_Ddl.Selected,
'Reserved Desk': Self_Section_Seat_Ddl.Selected,
'Booked By': Self_Section_EmployeeName_Ddl.Selected
}
)
)
);
// Store created 'Reservation' (parent) record in a variable 'newReservationRecord'
Set(
newReservationRecord,
First(ReservationRecord)
);
//Create 'Reservation Details' (child) record for each date
//Then associates with 'Reservation' (parent) record by 'Reservation Details'.'Reservation'
ForAll(
Sequence(
DateDiff(
FromDate_Dp.Value,
ToDate_Dp.Value,
TimeUnit.Days
) + 1
),
Patch(
'Reservation Details',
Defaults('Reservation Details'),
{
Date: DateAdd(
FromDate_Dp.Value,
Value - 1,
TimeUnit.Days
),
Reservation: newReservationRecord,
Name: newReservationRecord.'Reservation ID' & "_" & DateAdd(
FromDate_Dp.Value,
Value - 1,
TimeUnit.Days
),
'Reserved Desk': newReservationRecord.'Reserved Desk'
}
)
);
UpdateContext({Popup_Value: false});
UpdateContext({Confirmed_Popup_Value: true});
Thank you, and I appreciate any assistance and pointers given.
Hi @gymcode ,
Actually, I cannot find anything wrong in your formula that may cause this issue. However, I would like to help and modify the formula and see if it can work.
I assume BookingType_Self_Cb is a Check Box, so I use .Value instead of .Checked in the formula.
//Create new 'Reservation' (parent) record
//Store created 'Reservation' (parent) record in a variable 'newReservationRecord'
If(
BookingType_Self_Cb.Value,
Set(
newReservationRecord,
Patch(
Reservations,
Defaults(Reservations),
{
'Start Date': FromDate_Dp.Value,
'End Date': ToDate_Dp.Value,
'Reserved For': 'Reserved For (Reservations)'.Employee,
Facility: Building_Ddl.Selected,
Area: Area_Ddl.Selected,
'Employee Name': Self_Section_EmployeeName_Ddl.Selected,
'Reserved Desk': Self_Section_Seat_Ddl.Selected,
'Booked By': Self_Section_EmployeeName_Ddl.Selected
}
)
)
);
//Create 'Reservation Details' (child) record for each date
//Then associates with 'Reservation' (parent) record by 'Reservation Details'.'Reservation'
Patch(
'Reservation Details',
ForAll(
Sequence(
DateDiff(
FromDate_Dp.Value,
ToDate_Dp.Value,
TimeUnit.Days
) + 1
),
{
Date: DateAdd(
FromDate_Dp.Value,
Value - 1,
TimeUnit.Days
),
Reservation: newReservationRecord,
Name: newReservationRecord.'Reservation ID' & "_" & DateAdd(
FromDate_Dp.Value,
Value - 1,
TimeUnit.Days
),
'Reserved Desk': newReservationRecord.'Reserved Desk'
}
)
);
UpdateContext({Popup_Value: false});
UpdateContext({Confirmed_Popup_Value: true});
Best regards,