web
You’re offline. This is a read only version of the page.
close
Skip to main content
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);
        }
    );
}
I have the same question (0)
  • 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.

  • smar.sus Profile Picture
    35 on at
    RE: Lookup showing (No Name)

    Thank you so much!!

    It works!!

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Rishabh Kanaskar Profile Picture

Rishabh Kanaskar 235

#2
MVP-Daniyal Khaleel Profile Picture

MVP-Daniyal Khaleel 177

#3
Tom_Gioielli Profile Picture

Tom_Gioielli 156 Super User 2025 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans