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 / Power Fx Command Bar -...
Power Apps
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.

 

 

2024-02-26 09_14_57-Window.png
I have the same question (0)
  • Verified answer
    Rinalds33 Profile Picture
    62 on at

    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

Forum hierarchy changes are complete!

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

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 291 Most Valuable Professional

#2
Kalathiya Profile Picture

Kalathiya 282 Super User 2026 Season 1

#3
VASANTH KUMAR BALMADI Profile Picture

VASANTH KUMAR BALMADI 195

Last 30 days Overall leaderboard