Skip to main content

Notifications

Announcements

No record found.

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
    smar.sus 35 on at
    RE: Lookup showing (No Name)

    Thank you so much!!

    It works!!

  • Suggested answer
    XM-22040801-0 Profile Picture
    XM-22040801-0 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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,399 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans