{"id":729,"date":"2012-04-30T16:56:17","date_gmt":"2012-04-30T16:56:17","guid":{"rendered":"http:\/\/mahenderpal.wordpress.com\/?p=729"},"modified":"2012-04-30T16:56:17","modified_gmt":"2012-04-30T16:56:17","slug":"get-parent-customer-id-based-on-contact-id","status":"publish","type":"post","link":"https:\/\/himbap.com\/blog\/?p=729","title":{"rendered":"Get Parent Customer ID based on contact id"},"content":{"rendered":"<p>Requirement: Sometime we have requirement to get contact&#8217;s parent customer id.<\/p>\n<p>Solution: We can use REST retrieve method where we can pass record ID and get details from entiy<\/p>\n<p>function ParentCustomerID(ContactId) {<\/p>\n<p>var context = Xrm.Page.context;<br \/>\nvar serverUrl = context.getServerUrl(); \/\/Update: in MS CRM 2013 or 2015 you need to use getClientUrl() instead of getServerUrl()<br \/>\nvar ODataPath = serverUrl + &#8220;\/XRMServices\/2011\/OrganizationData.svc&#8221;;<br \/>\nvar retrieveParentCustomer= new XMLHttpRequest();<br \/>\nretrieveParentCustomer.open(&#8220;GET&#8221;, ODataPath + &#8220;\/<strong>ContactSet<\/strong>(guid'&#8221; + ContactId+ &#8220;&#8216;)&#8221;, false); \/\/Change entity if required<br \/>\nretrieveParentCustomer.setRequestHeader(&#8220;Accept&#8221;, &#8220;application\/json&#8221;);<br \/>\nretrieveParentCustomer.setRequestHeader(&#8220;Content-Type&#8221;, &#8220;application\/json; charset=utf-8&#8221;);<br \/>\nretrieveParentCustomer.onreadystatechange = function() {<br \/>\nretrieveParentCustomerCallBack(this);<br \/>\n};<br \/>\nretrieveParentCustomer.send();<\/p>\n<p>}<br \/>\nfunction retrieveParentCustomerCallBack(retrieveParentCustomer) {<br \/>\nif (retrieveParentCustomer.readyState == 4 \/* complete *\/) {<br \/>\nif (retrieveParentCustomer.status == 200) {<\/p>\n<p>var retrievedParent = this.parent.JSON.parse(retrieveParentCustomer.responseText).d;<\/p>\n<p>alert(retrievedParent.ParentCustomerId.Id); \/\/for id<br \/>\nalert(retrievedParent.ParentCustomerId.Name); \/\/for name<\/p>\n<p>}<\/p>\n<p>}}<\/p>\n<p>Enjoy !!!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Requirement: Sometime we have requirement to get contact&#8217;s parent customer id. Solution: We can use REST retrieve method where we can pass record ID and get details from entiy function ParentCustomerID(ContactId) { var context = Xrm.Page.context; var serverUrl = context.getServerUrl(); \/\/Update: in MS CRM 2013 or 2015 you need to use getClientUrl() instead of getServerUrl() var ODataPath = serverUrl +&#8230; <a href=\"https:\/\/himbap.com\/blog\/?p=729\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5],"tags":[],"_links":{"self":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/729"}],"collection":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=729"}],"version-history":[{"count":0,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/729\/revisions"}],"wp:attachment":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=729"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=729"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=729"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}