web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

i am getting Error:unable to get property 'getValue' of undefined or null reference in javascript

(0) ShareShare
ReportReport
Posted on by

hi,

i am getting Error:unable to get property 'getValue' of undefined or null reference in javascript

while i am writing a snippet to retrieve contactid from lookup.

here is my snippet:

function contactField_Onchange()
{
var jobTitle = Xrm.Page.data.entity.attributes.get("new_title");
var fullName = Xrm.Page.data.entity.attributes.get("new_fullname");
var emailAddress = Xrm.Page.data.entity.attributes.get("new_email");
var mobilePhone = Xrm.Page.data.entity.attributes.get("new_mobile");
var contactjobTitle = "";
var contactName = "";
var contactEmail = "";
var contactMobile = "";
///contact
//Get parentcustomerid lookup value
var lookupItem = new Array();
lookupItem = Xrm.Page.getAttribute("contactid").getValue(); //getting error here..

if (lookupItem != null)
{
var guid = lookupItem[0].id;
var parentcustomeridValue = guid;
var entType = lookupItem[0].entityType;
var parentcustomertypeValue = entType;
if (parentcustomeridValue != null && parentcustomertypeValue == "contact")
{
//get entity contact
var entity = "Contact";
var fields = "*";
var filter = "ContactId eq guid'" + parentcustomeridValue + "'";

var ret = retrieveMultipleSync(entity, filter, fields);

if (ret != null)
{
if (ret[0].jobtitle != null)
{
contactjobTitle = ret[0].jobtitle;
jobTitle.setValue(contactjobTitle);
}
if(ret[0].fullname != null)
{
contactName = ret[0].fullname;
fullName.setValue(contactName);
}
if(ret[0].emailaddress1 != null)
{
contactEmail = ret[0].emailaddress1;
emailAddress.setValue(contactEmail);
}
if(ret[0].mobilephone != null)
{
contactMobile = ret[0].mobilephone;
mobilePhone.setValue(contactMobile);
}
}
}
}
else
{
jobTitle.setValue(contactjobTitle);
fullName.setValue(contactName);
emailAddress.setValue(contactEmail);
mobilePhone.setValue(contactMobile);
}
}

can anyone help me to resolve this issue.

Thank You

Habeeb.

*This post is locked for comments

I have the same question (0)
  • Aileen Gusni Profile Picture
    44,524 on at

    Hi Habeeb,

    lookupItem = Xrm.Page.getAttribute("contactid").getValue(); //getting error here..

    Try change to this:

    lookupItem = Xrm.Page.getAttribute("contactid");

    Make sure that your attribute name is contacted, not new_contactid, or not another prefix.

  • Habeeb-Dynamics CRM Application Developer Profile Picture
    on at

    i have replaced this code with

    lookupItem = Xrm.Page.getAttribute("contactid");

    but it is giving "null"

    and my Contact schema name for Id is"contactid" only there is no error in this area.

  • Verified answer
    Aileen Gusni Profile Picture
    44,524 on at

    Hi, check to the Form Editor.

    What is the attribute name exactly?

  • Habeeb-Dynamics CRM Application Developer Profile Picture
    on at

    Hi ,

    My Entity requirement snapshot as follows:


     

    Here is my javascript Onchange function for contact lookupfield:

    function contactField_Onchange()
    {
    //debugger;
    var jobTitle = Xrm.Page.data.entity.attributes.get("new_title");
    var fullName = Xrm.Page.data.entity.attributes.get("new_fullname");
    var emailAddress = Xrm.Page.data.entity.attributes.get("new_email");
    var mobilePhone = Xrm.Page.data.entity.attributes.get("new_mobile");
    var contactjobTitle = "";
    var contactName = "";
    var contactEmail = "";
    var contactMobile = "";
    //contact
    //Get parentcustomerid lookup value
    var lookupItem = new Array();
    lookupItem = Xrm.Page.getAttribute("contactid").getValue();

    if (lookupItem != null)
    {
    var guid = lookupItem[0].id;
    var parentcustomeridValue = guid;
    var entType = lookupItem[0].entityType;
    var parentcustomertypeValue = entType;
    if (parentcustomeridValue != null && parentcustomertypeValue == "contact")
    {
    //get entity contact
    var entity = "Contact";
    var fields = "*";
    var filter = "ContactId eq guid'" + parentcustomeridValue + "'";
    //ContactId
    var ret = retrieveMultipleSync(entity, filter, fields);

    if (ret != null)
    {
    if (ret[0].jobtitle != null)
    {
    contactjobTitle = ret[0].jobtitle;
    jobTitle.setValue(contactjobTitle);
    }
    if(ret[0].fullname != null)
    {
    contactName = ret[0].fullname;
    fullName.setValue(contactName);
    }
    if(ret[0].emailaddress1 != null)
    {
    contactEmail = ret[0].emailaddress1;
    emailAddress.setValue(contactEmail);
    }
    if(ret[0].mobilephone != null)
    {
    contactMobile = ret[0].mobilephone;
    mobilePhone.setValue(contactMobile);
    }
    }
    }
    }
    else
    {
    jobTitle.setValue(contactjobTitle);
    fullName.setValue(contactName);
    emailAddress.setValue(contactEmail);
    mobilePhone.setValue(contactMobile);
    }
    }

    And one more thing i have changed and tried so many times my schema name [lookupItem Xrm.Page.getAttribute("contactid").getValue();]       

    from "contactid" to "new_contact" but it is giving same error.

    Could you please rectify this problem.

    Thank You

    Habeeb

  • Aileen Gusni Profile Picture
    44,524 on at

    Hi Habeeb,

    Don't try. But check the attribute name correctly, please

    Are you sure that it is new_contact?

    You don't need this .getValue for lookup

    lookupItem = Xrm.Page.getAttribute("new_contact");

    Assuming your attribute name is new_contact

  • Habeeb-Dynamics CRM Application Developer Profile Picture
    on at

    yeah my attribute name is correct.

    Could you plz check it once in my system through teamviewer.

    Thank You.

  • Verified answer
    Aileen Gusni Profile Picture
    44,524 on at

    I saw in different post, which is I assume you are and the other post's author are working in the same company and maybe same project.

    He puts new_primarycontact as the contact lookup id.

    Please confirm this.

  • Verified answer
    Habeeb-Dynamics CRM Application Developer Profile Picture
    on at

    Thanks all of you..i got solution.

  • Silve1999 Profile Picture
    455 on at

    can you share the solution?

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans