Quantcast
Channel: Microsoft Dynamics CRM
Viewing all articles
Browse latest Browse all 123975

Forum Post: RE: Getting Parent Entity in Code

$
0
0

The easiest way if just to place the fields you need on the form. If nobody needs to see/access them, put them in a separate section and turn off the the option to make it visible - this way the fields technically still render on the form and can be access via JavaScript but users won't be bothered with extra information. 

But if this really isn't an option, you can make a call to the OData endpoint and retrieve values from the record (or other records).

This example looks up the Parent Customer of a Contact - running from a Contact record - hope it helps

var serverUrl = Xrm.Page.context.getClientUrl(); var oDataSelect = serverUrl + "/XRMServices/2011/OrganizationData.svc/ContactSet?$select=ParentCustomerId&$filter=ContactId eq guid'" + Xrm.Page.data.entity.getId() + "'";  var retrieveReq = new XMLHttpRequest(); retrieveReq.open("GET", oDataSelect, false); retrieveReq.setRequestHeader("Accept", "application/json"); retrieveReq.setRequestHeader("Content-Type", "application/json;charset=utf-8"); retrieveReq.onreadystatechange = function () {  if (retrieveReq.readyState == 4) {   if (retrieveReq.status == 200) {    var retrieved = JSON.parse(retrieveReq.responseText).d;    alert(retrieved.results[0].ParentCustomerId.Id);   }  }; } retrieveReq.send(); 

Viewing all articles
Browse latest Browse all 123975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>