Contact entities in CRM 2011 have a lot of built-in fields, and I've added some custom fields as well.
I want to fetch all field names as a list using Javascript. If you want to create a email template, CRM will let you choose from all of the fields from a dialog. I'd like to get the field names and values as they appear in that dialog.
I used the following code to fetch all attributes for a contact, but this list includes all object properties, not 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;
When I inspect the entity object using IE developer tools, it shows me all of the contact's properties, but with different names. For example, in CRM Contact, there is a field mobilephone, but in IE it is entity.MobilePhone. Further, IE does not display any of the custom fields.