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)

Retrieve the phone number from the account entity to contact entity

(0) ShareShare
ReportReport
Posted on by 385

Retrieve the phone number from the account entity to contact entity , when the company name is selected from the  lookup, can any one rectify the error in the program below.

function getRecordDetails() {

var EntityName, EntityId, LookupFieldObject;

var Name = "";

var resultXml;

LookupFieldObject = Xrm.Page.data.entity.attributes.get('parentaccountid');

if (LookupFieldObject.getValue() != null) {

EntityId = LookupFieldObject.getValue()[0].id;

EntityName = LookupFieldObject.getValue()[0].entityType;

resultXml = getDetails(EntityName, EntityId);


// Retrieve text field value and set the value to current record field.

if (resultXml != null && resultXml.attributes['new_telephone1'] != null) {

var industrydetail = resultXml.attributes['new_telephone1'].value;

Xrm.Page.data.entity.attributes.get('new_mobilephone').setValue(industrydetail);

}

else

Xrm.Page.data.entity.attributes.get('new_mobilephone').setValue("");


}

}

function getDetails(EntityName, EntityId) {

var cols = ["new_telephone1","primarycontactid"];

var retrievedResult = XrmServiceToolkit.Soap.Retrieve(EntityName, EntityId, cols);

return retrievedResult;

}

*This post is locked for comments

I have the same question (0)
  • Hosk Profile Picture
    on at

    Do you get an error?  What happens when it's run

  • Bob Hatcher Profile Picture
    on at

    What's the error?

    The F12 debugger is great. Click the bug on the left side, find your function and set a breakpoint. Then walk through it step by step.

  • Suggested answer
    Community Member Profile Picture
    on at

    Hi Sruthi,

    Please see attached javascript example based on the out of box CRM 2013 organisation customization.

    Hope it helps.

    Regards,

    Jacqui

  • Amritha Profile Picture
    385 on at

    Error: null is null or not an object

  • Suggested answer
    Amritha Profile Picture
    385 on at

    adding this functions within form properties, so i wont be able to debugg.

  • Community Member Profile Picture
    on at

    See the updated JS attached below. I've made mirror changes and have tested - it works with my out of box organisation. 

    Cheers,

    Jacqui

     

  • Royal King Profile Picture
    27,686 on at

    Rather than doing it using javascript create a real-time workflow to populate the phone number from account to contact on change of the parent account.

    You can use REST builder tool to generate all REST javascript function from  below url rather writing it yourself.

    https://crmrestbuilder.codeplex.com/

    Here is the javascript function that retrieves parent customer Phone number. Replace the select field name with whatever fields you want to retrieve from account entity. Field names should be Schema Names of the fields

    function getAccountPhoneNumber()
    {
    var customerid= Xrm.Page.getAttribute("parentcustomerid").getValue();
    if( customerid != null && customerid[0].id)
    {
    var req = new XMLHttpRequest();
    req.open("GET", encodeURI(Xrm.Page.context.getClientUrl() + "/XRMServices/2011/OrganizationData.svc/AccountSet(guid'"+customerid[0].id+"')?$select=Address1_Telephone1,Address1_Telephone2,Address1_Telephone3,Telephone1,Telephone2,Telephone3&$expand=equipment_accounts"), false);
    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(req.responseText).d;
    var Address1_Telephone1 = result.Address1_Telephone1;
    var Address1_Telephone2 = result.Address1_Telephone2;
    var Address1_Telephone3 = result.Address1_Telephone3;
    var Telephone1 = result.Telephone1;
    var Telephone2 = result.Telephone2;
    var Telephone3 = result.Telephone3;
    }
    else {
    alert(this.statusText);
    }
    }
    };
    req.send();
    }
    }

  • Suggested answer
    Amritha Profile Picture
    385 on at

    Hi Chitra , thank you.....

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 March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
JS-09031509-0 Profile Picture

JS-09031509-0 3

#2
AS-17030037-0 Profile Picture

AS-17030037-0 2

#2
Mark Eckert Profile Picture

Mark Eckert 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans