Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Unanswered

Display a lookup column in one entity created in another entity

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?

  • Rajath Krishna S Profile Picture
    Rajath Krishna S 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
    Ray 1,505 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
    Rajath Krishna S 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
    Ray 1,505 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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans