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,...
Unanswered

Display a lookup column in one entity created in another entity

(0) ShareShare
ReportReport
Posted on by 62

I have created a field named as "Customer Name" in both "Rebate & Approvals" entity and  "Test 123" entity. If anyone enters the customer name in Rebate & Approvals then it has to display in  Test 123 entity.

I wrote a javascript for that in OnLoad form property but the error is showing as "cannot read properties of null. getvalue()

pastedimage1659600096097v1.png

if (results != null) {
if ((results[0].value[0].new_customername) != null)
{
var _CustomerNameObj = (result[0].value[0].new_customername);
var _CustomerNameValue = _CustomerNameObj._CustomerNameObj[0].name;
Xrm.Page.getAttribute("new_customername").setValue(_CustomerNameValue[0].name);
}

This is the null property where error is showing.

Can anyone help me in solving this?

I have the same question (0)
  • Rajath Krishna S Profile Picture
    62 on at
    RE: Display a lookup column in one entity created in another entity

    I have given the input to the respective field but its not updating. I am pasting the full script for your reference.

    function RebateToOfg()

    {

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

     {

       var vOppid1 =  Xrm.Page.getAttribute("new_new_test123_new_rebateapprovalsoas").getValue()[0].id;

       vOppid1 = vOppid1.replace("{","").replace("}","");

       var req = new XMLHttpRequest();

       req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/opportunities?$select=_contactid_value,_customerid_value,description,name&$filter=opportunityid eq "+vOppid1+"", 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.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");

       req.onreadystatechange = function() {

           if (this.readyState === 4) {

               req.onreadystatechange = null;

               if (this.status === 200) {

                   var results = JSON.parse(this.response);

                   for (var i = 0; i < results.value.length; i++) {

                       var _contactid_value = results.value[i]["_contactid_value"];

                       var _contactid_value_formatted = results.value[i]["_contactid_value@OData.Community.Display.V1.FormattedValue"];

                       var _contactid_value_lookuplogicalname = results.value[i]["_contactid_value@Microsoft.Dynamics.CRM.lookuplogicalname"];

                       var _customerid_value = results.value[i]["_customerid_value"];

                       var _customerid_value_formatted = results.value[i]["_customerid_value@OData.Community.Display.V1.FormattedValue"];

                       var _customerid_value_lookuplogicalname = results.value[i]["_customerid_value@Microsoft.Dynamics.CRM.lookuplogicalname"];

                       var description = results.value[i]["description"];

                       var name = results.value[i]["name"];

                   }

               } else {

                   Xrm.Utility.alertDialog(this.statusText);

               }

           }

       };

       req.send();

    if (result != null) {

       if ((result[0].value[0].header_new_customername) != null)

           {

               var _CustomerNameObj = (result[0].value[0].header_new_customername);

               var _CustomerNameValue = _CustomerNameObj._CustomerNameObj[0].name;

               Xrm.Page.getAttribute("header_new_customername").setValue(_CustomerNameValue[0].name);

           }

       }

    }

    }

    }

  • Ray Profile Picture
    1,537 on at
    RE: Display a lookup column in one entity created in another entity

    I think the "new_new_test123_new_rebateapprovalsoas" attribute has no value so you get the error.

  • Rajath Krishna S Profile Picture
    62 on at
    RE: Display a lookup column in one entity created in another entity

    Hi,

    function RebateToOfg()

    {

       var vOppid1 =  Xrm.Page.getAttribute("new_new_test123_new_rebateapprovalsoas").getValue()[0].id;

    This is the getvalue() line in my js code

  • Ray Profile Picture
    1,537 on at
    RE: Display a lookup column in one entity created in another entity

    Hi,

    Error log says 'getValue' but the code you showed not include the 'getValue' and I think need more info to answer your question.

    Also you can download the error log and open it, then you should search your JS name, and the number after the JS name, it is the error code line, so you can check the line.

    Here is an example error log:

    TypeError: Cannot read properties of null (reading 'setVisible')
    at enableTechnicianLookup (xxxxx.crm.dynamics.com/.../MyJS.js:5451:68)

    In this example, my JS file name is "MyJS.js" and 5451 is the error code line so I need to check line 5451.

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…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
DAnny3211 Profile Picture

DAnny3211 134

#2
Daniyal Khaleel Profile Picture

Daniyal Khaleel 115

#3
Abhilash Warrier Profile Picture

Abhilash Warrier 70 Super User 2025 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans