In CRM 2011, the contact entities come with a variety of default fields, and I have also included some custom fields.
My goal is to retrieve all field names in a JavaScript list. When creating an email template in CRM, you can select fields from a dialog. I am looking to extract the field names and values as shown in that dialog.
The code snippet below was meant to fetch all attributes for a contact. However, it returns all object properties rather than just the contact fields.
ODataPath = GetServerUrl() + "/XRMServices/2011/OrganizationData.svc";
var retrieveRecordsReq = new XMLHttpRequest();
var result = "";
retrieveRecordsReq.open('GET', ODataPath + "/AccountSet(guid'" + guid + "')", false);
retrieveRecordsReq.setRequestHeader("Accept", "application/json");
retrieveRecordsReq.setRequestHeader("Content-Type", "application/json; charset=utf-8");
retrieveRecordsReq.send();
var entity = JSON.parse(retrieveRecordsReq.responseText).d;
Upon inspecting the entity
object using IE developer tools, I noticed that all of the contact's properties are displayed with different names. For instance, while CRM Contact has a field called mobilephone
, in IE it is referred to as entity.MobilePhone
. Additionally, IE does not show any of the custom fields.