Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Microsoft Dataverse
Answered

Power Fx Command Bar - Patch Subgrid Selected Lookup fields (Model Driven App)

(0) ShareShare
ReportReport
Posted on by 62

Hello,

I'm currently working on a solution to patch the lookup field in a subgrid for all selected child items.

Here's the scenario:

I have a parent Dataverse table named "Reservation" and a related child table named "Bookings" with a 1:N relationship. When a user opens the Reservation form, they encounter a subgrid displaying all Booking items where the "Reservation" lookup column is empty.

My objective is to enable users to select multiple items in the subgrid and then patch the "Reservation" lookup column with the current reservation.

I was trying to use following formula but can't find a way how to get data to patch Reservation column:

Patch(
 'Booking Suggestions',
 ForAll(
 Self.Selected.AllItems,
 Patch(
 ThisRecord,
 {Reservation: Self.Selected.Item.Reservation}
 )
 )
);



Any guidance or assistance on achieving this would be greatly appreciated.

 

 

  • Verified answer
    Rinalds33 Profile Picture
    62 on at
    Re: Power Fx Command Bar - Patch Subgrid Selected Lookup fields (Model Driven App)

    Found a solution by myself using javascript, if someone facing the same issue here is the code that will work.

     

    function getTotalEstimatedRevenue() {
     var selectedReservation = Xrm.Page.data.entity.getId();
    
    
     var updateData = {
     // Ensure the correct logical name and binding for the lookup field
     "<look up entity>@odata.bind":
     "/<lookup in plural>(" +
     selectedReservation.replace("{", "").replace("}", "").toLowerCase() +
     ")",
     };
     console.log("Update Data:", updateData);
    
     Xrm.Page.getControl("<Control Name>")
     .getGrid()
     .getSelectedRows()
     .forEach(function (row, i) {
     var selectedItemGuid = row.getData().getEntity().getId();
    
     Xrm.WebApi.updateRecord(
     "<Table name>",
     selectedItemGuid,
     updateData
     ).then(
     function success(result) {
     console.log("Record updated");
     },
     function (error) {
     console.log("Error updating record: ", error);
     }
     );
     });
    
     // Alert for debugging purposes
     alert("The total estimated revenue of all opportunities is ");
    }

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

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Leaderboard > Power Apps - Microsoft Dataverse

#1
mmbr1606 Profile Picture

mmbr1606 22 Super User 2025 Season 1

#2
stampcoin Profile Picture

stampcoin 19

#3
Michael E. Gernaey Profile Picture

Michael E. Gernaey 15 Super User 2025 Season 1

Overall leaderboard

Featured topics