简体   繁体   English

Dynamics API返回实体字段和字段元数据

[英]Dynamics API returning entity fields and field metadata

We can get the entity metadata in Dynamics API it returns all of the fields that are in the entity. 我们可以在Dynamics API中获取实体元数据,它会返回实体中的所有字段。 What I would like to know is it possible to get the metadata for the fields at the same time? 我想知道是否可以同时获取字段的元数据?

var request = new RetrieveEntityRequest
            {
                EntityFilters = EntityFilters.All,
                LogicalName = entityName,
                RetrieveAsIfPublished = true,


            };
            var response = (RetrieveEntityResponse)_organisationService.Execute(request);

            return response != null ? response.EntityMetadata : null;

Your code already answers your question but you can optimize it like this: 您的代码已经回答了您的问题,但是您可以像这样进行优化:

    private EntityMetadata GetEntityMetadata(string entityName, EntityFilters entityFilters, bool retrieveAsIfPublished = false)
    {
        var request = new RetrieveEntityRequest
        {
            EntityFilters = entityFilters,
            LogicalName = entityName,
            RetrieveAsIfPublished = retrieveAsIfPublished,
        };

        var response = (RetrieveEntityResponse)_service.Execute(request);

        return response?.EntityMetadata;
    }

If you just need Entity and Attributes metadata you can call the previous method this way: 如果只需要实体和属性元数据,则可以通过以下方式调用先前的方法:

        var entityMetadata = GetEntityMetadata("[entityname]", EntityFilters.Attributes | EntityFilters.Entity);
        var attributeMetadata = entityMetadata?.Attributes;

Using WebAPI you can do so 使用WebAPI可以做到

[organization url]/api/data/v8.2/EntityDefinitions?$select=DisplayName,EntitySetName&$filter=SchemaName%20eq%20%27Account%27

This gives you the metadataID for the account record in your CRM instance. 这为您提供了CRM实例中帐户记录的元数据ID。 Now use that value to create another API call and get the specific attributes for this. 现在,使用该值创建另一个API调用,并为此获取特定的属性。 Here is the next API call: 这是下一个API调用:

[organization url]/api/data/v8.2/EntityDefinitions(GUID)?$select=LogicalName&$expand=Attributes($select=LogicalName)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM