문제

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.

도움이 되었습니까?

해결책 2

Your solution for get a list of all attribute is correct. as Guido told it is Schema Name.

i test your code and add some line off Codes for create a list off all attribute:

ODataPath = GetServerUrl() + "/XRMServices/2011/OrganizationData.svc";

var retrieveRecordsReq = new XMLHttpRequest();
var url = "";

if (entityname == 'account')
    url = "/AccountSet(guid'" + guid + "')";
else if (entityname == 'contact')
    url = "/ContactSet(guid'" + guid + "')";
else if (entityname == 'lead')
    url = "/LeadSet(guid'" + guid + "')";
else if (entityname == 'systemuser')
    url = "/SystemUserSet(guid'" + guid + "')";

retrieveRecordsReq.open('GET', ODataPath + url, false);
retrieveRecordsReq.setRequestHeader("Accept", "application/json");
retrieveRecordsReq.setRequestHeader("Content-Type", "application/json; charset=utf-8");
retrieveRecordsReq.send();

var entity = JSON.parse(retrieveRecordsReq.responseText).d;
var AllContactFields = new Array();

for(var x in entity)
{
    if (typeof entity[x] == 'object') {
        if (entity[x] == null)
            AllContactFields.push(x);
    }
    else {
        AllContactFields.push(x);
    }
}

the AllContactFields array is the result list.

Good Luck

다른 팁

You don't get different names, with the REST endpoint you get the Schema Name.

Read this article for more information: http://www.mohamedibrahim.net/blog/2012/10/04/dynamics-crm-entity-and-field-display-name-field-schema-name-and-field-logical-name-attribute-name/

The entity contains also the custom fields, the endpoint returns all fields, OOB and custom one.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top