Get Parent Customer ID based on contact id
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.

Like
Report
*This post is locked for comments