Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Microsoft Dataverse
Unanswered

Several fields in a form from a related entity

(0) ShareShare
ReportReport
Posted on by 144

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.

Order.PNG

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.

 

 

 

  • EricRegnier Profile Picture
    8,714 Most Valuable Professional on at
    Re: Several fields in a form from a related entityO

    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
    }

     

     

  • summitb Profile Picture
    on at
    Re: Several fields in a form from a related entityO

    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');
     }
     });

     

  • TrulsB Profile Picture
    144 on at
    Re: Several fields in a form from a related entityO

    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?

     

     

     
    Is it possible to fill in these fields for telephone and e-mail automatically with data from the Customer table?
  • summitb Profile Picture
    on at
    Re: Several fields in a form from a related entity

    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

  • EricRegnier Profile Picture
    8,714 Most Valuable Professional on at
    Re: Several fields in a form from a related entity

    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!

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

🌸 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…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Power Apps - Microsoft Dataverse

#1
stampcoin Profile Picture

stampcoin 17

#2
mmbr1606 Profile Picture

mmbr1606 15 Super User 2025 Season 1

#3
ankit_singhal Profile Picture

ankit_singhal 11 Super User 2025 Season 1

Overall leaderboard

Featured topics