web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Patch Formula Failed t...
Power Apps
Answered

Patch Formula Failed to Create New Parent Record, and Associates Child Record to Previously Created Parent

(0) ShareShare
ReportReport
Posted on by 473

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

gymcode_2-1706190805614.png


2) Reservation Details cancelled for 25-Jan only

gymcode_3-1706190924701.png


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: 
gymcode_4-1706191100129.png


5) New Reservation (parent) failed to create.
New Reservation Detail (child) is created, but associated to previous Reservation (parent) above, which is incorrect.

gymcode_5-1706191334311.png


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.

Categories:
I have the same question (0)
  • Verified answer
    v-jefferni Profile Picture
    on at

    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,

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 739 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard