Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

Lookup showing (No Name)

(0) ShareShare
ReportReport
Posted on by 35

Hi,

In the case form I want to autofill Company Lookup field as soon as Project Lookup field is set. (OnChange)

Generally it works but it shows (No Name) instead of the company name, so when i click on No name, it forwards me to the correct company.

I am retrieving the Project data and getting the company id, then I retrieve via relationship the comany name.

My code looks like this

function setCompany(executionContext) {

    var formContext = executionContext.getFormContext();
    // Get the value of lookup field A
    var project = formContext.getAttribute("skt_pde_project").getValue();

    // Get the record associated with lookup field A
    var project = project[0].id;

    // Retrieve the value of field B from the associated record
    Xrm.WebApi.retrieveRecord("pde_project", project, "?$select=_pde_account_id_value").then(
        function success(result) {
            console.log(result);
            // Columns
            var pde_projectid = result["pde_projectid"]; // Guid
            var pde_account_id = result["_pde_account_id_value"]; // Lookup
            var pde_account_id_formatted = result["_pde_account_id_value@OData.Community.Display.V1.FormattedValue"];
            var pde_account_id_lookuplogicalname = result["_pde_account_id_value@Microsoft.Dynamics.CRM.lookuplogicalname"];

            if (result.hasOwnProperty("pde_account_id") && result["pde_account_id"] !== null) {
                var pde_account_id_name = result["pde_account_id"]["name"]; // Text

            }      
            // Set the value of lookup field B
            formContext.getAttribute("customerid").setValue([{ id: pde_account_id, name: pde_account_id_name, entityType: pde_account_id_lookuplogicalname }]);
        },
        function (error) {
            console.log(error.message);
        }
    );
}
  • smar.sus Profile Picture
    35 on at
    RE: Lookup showing (No Name)

    Thank you so much!!

    It works!!

  • Suggested answer
    XM-22040801-0 Profile Picture
    11 on at
    RE: Lookup showing (No Name)

    Hi,

    pde_account_id_name (variable) will be allways undefined because you don't get the pde_account_id node in your Xrm.WebApi.retrieveRecord() call.

    Change:

    Xrm.WebApi.retrieveRecord("pde_project", project, "?$select=_pde_account_id_value")

    To:

    Xrm.WebApi.retrieveRecord("pde_project", project, "?$select=_pde_account_id_value&$expand=pde_account_id($select=name)")

    $expand=pde_account_id($select=name) will add the pde_account_id node in your result.

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

Jainam Kothari – Community Spotlight

We are honored to recognize Jainam Kothari as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

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

Leaderboard >

Product updates

Dynamics 365 release plans