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 :
Dynamics 365 Community / Blogs / HIMBAP / Get Parent Customer ID base...

Get Parent Customer ID based on contact id

Mahendar Pal Profile Picture Mahendar Pal 45,095

sometime we have requirement to get contact’s parent customer id, if you have same requirment you can use below code, make sure

function ParentCustomerID(ContactId) {

    var context = Xrm.Page.context;
    var serverUrl = context.getServerUrl();
    var ODataPath = serverUrl + “/XRMServices/2011/OrganizationData.svc”;
    var retrieveParentCustomer= new XMLHttpRequest();
    retrieveParentCustomer.open(“GET”, ODataPath + “/ContactSet(guid’” + ContactId+ “‘)”, false);
    retrieveParentCustomer.setRequestHeader(“Accept”, “application/json”);
    retrieveParentCustomer.setRequestHeader(“Content-Type”, “application/json; charset=utf-8″);
    retrieveParentCustomer.onreadystatechange = function() {
        retrieveParentCustomerCallBack(this);
    };
    retrieveParentCustomer.send();

}
function retrieveParentCustomerCallBack(retrieveParentCustomer) {
    if (retrieveParentCustomer.readyState == 4 /* complete */) {
        if (retrieveParentCustomer.status == 200) {

            var retrievedParent = this.parent.JSON.parse(retrieveParentCustomer.responseText).d;

                    alert(retrievedParent.ParentCustomerId.Id); //for id
                    alert(retrievedParent.ParentCustomerId.Name); //for name

}
  
}}

Enjoy !!!



This was originally posted here.

Comments

*This post is locked for comments