I have a two entities with a relationship between two fields. I use model-driven application, and form that is customized. The Customer Name in Order entity is a Lookup field to Customer.
I have a Customer endity with relation to Order Entity.
In my order form in CDS, i have added the Customer Name, and the lookup to Customer works well.
My question is: How to i add the e-mail and phone number (from Customer entity) to the Order form. I must have the e-mail and phone fields for the selected customer in the Order form.
Hi @TrulsB, not sure if you already resolved this, but if you create a quick view form with those fields on it will automatically display on the order form as soon as you select the customer lookup. My recommendation is to as much as possible stay away from custom code (aka customizations) and try to leverage out-of-the-box.
BTW the code provided by @summitb uses deprecated code such as Xrm.Page. If you do end up using JavaScript, suggest to use the Xrm.WebApi.retrieveRecord rather than jQuery. Here's the updated (untested) supported code:
async function OnCustomerChanged(context) {
let formContext = context.getFormContext();
if(!formContext.getAttribute("customerid").getValue()) return;
let customerId = formContext.getAttribute("customerid").getValue()[0].id;
let customer = await Xrm.WebApi.retrieveRecord("account", customerId, "?$select=phonenumber,emailaddress1");
formContext.getAttribute("telephone").setValue(customer.phonenumber);
//set other fields
}
You can do use web-resource to populate it in the form. You can put something like this onLoad event.
var customerid = Xrm.Page.getAttribute("customerid").getValue()[0].id;
var urlSelect = "http://YourServer//api/data/v9.1/" +
"/Customers?$select=email&$filter=customerid eq guid'" + customerid + "'";
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
datatype: "json",
url: urlSelect,
beforeSend: function (XMLHttpRequest) {
XMLHttpRequest.setRequestHeader("Accept", "application/json");
},
success: function (data, textStatus, XmlHttpRequest) {
Xrm.Page.data.entity.attributes.get("telephone").setValue(data.d.results[0].email);
},
error: function (XmlHttpRequest, textStatus, errorThrown) {
alert('Error');
}
});
Ok, thanks for the tip With the Quick View form.
In the order table/form, i have lookup to the Customer table (Customer Field).
In the Order form, i like to have one Field for phone, and one Field for e-mail. Is it possible to fill in these Field for phone and e-mail automaticly With data from the actual Customer record?
You can use a Quick view form in the Order form. A quick view control on a model-driven app form displays data from a record that is selected in a lookup on the form. The data displayed in the control is defined using a quick view form. The data displayed is not editable, but when the primary field is included in the quick view form, it becomes a link to open the related record. More information: Create and edit quick view forms
Hi @TrulsB,
You can easily achieve this with Quick View Forms. Quick View Forms allows to display fields from the related entity to the parent entity's form. The advantage of quick view forms is that you don't have to re-create these fields on the Order entity and sync/maintain the values as they change. They reference the data directly from the source entity (i.e. Customer).
Here's are the simple steps to create a customer quick view form and add it to your order form:
https://docs.microsoft.com/en-us/powerapps/maker/model-driven-apps/create-edit-quick-view-forms
Hope this helps!
stampcoin
17
mmbr1606
15
Super User 2025 Season 1
ankit_singhal
11
Super User 2025 Season 1