如何从CRM获取实体记录

时间:2015-03-30 10:06:44

标签: c# crm dynamics-crm-2015

我是MS-CRM的新手,我希望了解联系人的所有细节

     var executeQuickFindRequest = new OrganizationRequest("ExecuteQuickFind");
            executeQuickFindRequest.Parameters = new ParameterCollection();


            var entities = new List<string> { "contact", "lead", "account" };                //specify search term                
            executeQuickFindRequest.Parameters.Add("SearchText", "maria");
            //will cause serialisation exception if we don't convert to array                
            executeQuickFindRequest.Parameters.Add("EntityNames", entities.ToArray());

            var executeQuickFindResponse = _orgService.Execute(executeQuickFindRequest);
            var result = executeQuickFindResponse.Results;

此处显示的数据包含显示名称,例如address_1_Cityemail_user

但是,我希望得到AddressEmail等实际名称

由于

3 个答案:

答案 0 :(得分:1)

据我所知,您需要将其与该请求的实体属性配对。以下是如何检索实体的示例:

RetrieveEntityRequest retrieveBankAccountEntityRequest = new RetrieveEntityRequest
{
 EntityFilters = EntityFilters.Entity,
 LogicalName = entityName
};
RetrieveEntityResponse retrieveEntityResponse = (RetrieveEntityResponse)_serviceProxy.Execute(retrieveBankAccountEntityRequest);

答案 1 :(得分:1)

只是为了扩展BlueSam上面提到的内容。

EntityMetadata entityMetaData = retrieveEntityResponse.EntityMetadata;
for (int count = 0; count < entityMetaData.Attributes.ToList().Count; count++)
{
    if (entityMetaData.Attributes.ToList()[count].DisplayName.LocalizedLabels.Count > 0)
    {
        string displayName = entityMetaData.Attributes.ToList()[count].DisplayName.LocalizedLabels[0].Label;
        string logicalName = entityMetaData.Attributes.ToList()[count].LogicalName;
        AttributeTypeCode dataType = (AttributeTypeCode)entityMetaData.Attributes.ToList()[count].AttributeType;
    }
}

上面的代码将帮助您获取实体中每个属性的显示名称,逻辑名称和数据类型。同样,您也可以根据上面的代码片段从entityMetaData对象获取其他信息。

答案 2 :(得分:-1)

您可以轻松完成以下操作

       using (var service =  new  OrganizationService(CrmConnection.Parse("CRMConnectionString")))
    {
var Res = service.Retrieve("sv_answer", new Guid("GUID Of Record"), new ColumnSet("ColumnName "));
    }