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.
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 ");
}
mmbr1606
22
Super User 2025 Season 1
stampcoin
19
Michael E. Gernaey
15
Super User 2025 Season 1