Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Lookup shows "no name" after a value is populated

(0) ShareShare
ReportReport
Posted on by 310

Hello,

We are using CRM Online version 9.1

Have implemented this code to populate value from Accounts to Invoice (Contact lookup) on onChange of Customer field.

function test()

{
if(Xrm.Page.getAttribute("customerid").getValue()!=null)

//read

var opportunity = Xrm.Page.getAttribute("customerid").getValue()[0].id;

var opportunityId = opportunity.substring(1, 37);

opportunityId = opportunityId.replace('{', '').replace('}', '');

var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v9.1/accounts(" + opportunityId + ")?$select=_new_invoicetocontactname_value", true);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.onreadystatechange = function() {
    if (this.readyState === 4) {
        req.onreadystatechange = null;
        if (this.status === 200) {
                var result = JSON.parse(this.response);
                var _new_invoicetocontactname_value = result["_new_invoicetocontactname_value"];
                var _new_invoicetocontactname_value_formatted = result["_new_invoicetocontactname_value@OData.Community.Display.V1.FormattedValue"];
                var _new_invoicetocontactname_value_lookuplogicalname = result["_new_invoicetocontactname_value@Microsoft.Dynamics.CRM.lookuplogicalname"];
                
                var lookupValue = new Array();
                lookupValue[0] = new Object();
                lookupValue[0].id =_new_invoicetocontactname_value; // GUID of the lookup id
                lookupValue[0].name = _new_invoicetocontactname_value_formatted; // Name of the lookup
                lookupValue[0].entityType = "contact"; //Entity Type of the lookup entity
                Xrm.Page.getAttribute("new_invoicetocontactname").setValue(lookupValue);

            } else {
                Xrm.Utility.alertDialog(this.statusText);
            }
        }
    };
    req.send();

}


After value is populated, it shows no name in the lookup and shows correct value when the record is saved.

I have already asked about this here https://community.dynamics.com/crm/f/117/p/350287/938135#938135 but haven't got the solution yet.

Any help would be appreciated.
Thanx.

*This post is locked for comments

  • Clint Woods Profile Picture
    Clint Woods 1,031 on at
    RE: Lookup shows "no name" after a value is populated

    @Huzefa Bootwala I think you need to validate your select statement in the debugger. is the attribute name correct? "_new_invoicetocontactname_value". See what values it returns.

  • Huzefa Bootwala Profile Picture
    Huzefa Bootwala 310 on at
    RE: Lookup shows "no name" after a value is populated

    I added alert after the id and name is assigned to a variable.

    The id which I got is the correct value of a Contact record but the name says undefined.

  • Huzefa Bootwala Profile Picture
    Huzefa Bootwala 310 on at
    RE: Lookup shows "no name" after a value is populated

    Hi, I did this and it worked perfectly fine

    var lookupValue = new Array();
                    lookupValue[0] = new Object();
                    lookupValue[0].id = "{2466ABB2-0951-E911-A96F-000D3AD24182}"; // GUID of the lookup id
                    lookupValue[0].name = "Huzefa Bootwala"; // Name of the lookup
                    lookupValue[0].entityType = "contact"; //Entity Type of the lookup entity
                    Xrm.Page.getAttribute("new_invoicetocontactname").setValue(lookupValue);


    And even the code works fine but only after I save the record.

  • gdas Profile Picture
    gdas 50,089 on at
    RE: Lookup shows "no name" after a value is populated

    Try to use hard code value to see if your code is working fine or not .  Then proceed with dynamics value .

    community.dynamics.com/.../how-to-set-lookup-field-value-using-javascript-dynamics-crm

    With that debug your code and compare what value you are assigning in the lookup you will definitely find the root cause.

  • Huzefa Bootwala Profile Picture
    Huzefa Bootwala 310 on at
    RE: Lookup shows "no name" after a value is populated

    Hi,

    It says this Name: undefined

    It means its not getting the name of the record for lookup. But then how does it get the name on onSave?

    What is the solution for this?

    Thanx.

  • Suggested answer
    Dynamics365 Rocker Profile Picture
    Dynamics365 Rocker 7,755 on at
    RE: Lookup shows "no name" after a value is populated

    Can you please check below code:

    alert("Name is :"+ _new_invoicetocontactname_value_formatted);

    Let me know if you are getting name of record in alert.

  • Huzefa Bootwala Profile Picture
    Huzefa Bootwala 310 on at
    RE: Lookup shows "no name" after a value is populated

    Hi Stefan,

    Lookup value is from "Contact" entity. It has value in the First Name and Last Name fields.

    Not sure if this is the answer to your question.

    Thanx.

  • StefanS365 Profile Picture
    StefanS365 3,573 Most Valuable Professional on at
    RE: Lookup shows "no name" after a value is populated

    Hi Huzefa,

    Does the record in the lookup have a value for the Name field?

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

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

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

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,407 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans