简体   繁体   English

如何在CRM 2016中检索实体名称

[英]How to retrieve entity names in CRM 2016

In our solution, we are building HTTP/ODATA requests dynamically. 在我们的解决方案中,我们正在动态构建HTTP / ODATA请求。

For example, we will build a URL that looks like this: 例如,我们将构建一个如下所示的URL:

[http://org....api/v8.1/]accounts(00000000-0000-0000-0000-000000000001)/primarycontactid?$select=fullname

How do we dynamically get a list of all the entities such as 'accounts'? 我们如何动态获取所有实体的列表,例如“帐户”?

In 2011, we would simply execute against LeadSet/AccountSet/etcSet, what is the strategy in 2016? 在2011年,我们只需针对LeadSet / AccountSet / etcSet执行,2016年的战略是什么?

I don't know if there is some "language" trick (obviously the name of the set is just plural name in english of the entity, but that's not good enough for me), so I it like that - simply call webAPI metadata: 我不知道是否有一些“语言”技巧(显然该集的名称只是实体的英文中的复数名称,但这对我来说还不够好),所以我喜欢它 - 只需调用webAPI元数据:

http://[crmurl]/api/data/v8.2/EntityDefinitions?$select=EntitySetName,LogicalName&$filter=LogicalName eq 'account'

result is the following: 结果如下:

{
  "@odata.context":"http://[crmurl]/api/data/v8.2/$metadata#EntityDefinitions(EntitySetName,LogicalName)","value":[
    {
      "EntitySetName":"accounts","LogicalName":"account","MetadataId":"70816501-edb9-4740-a16c-6a5efbc05d84"
    }
  ]
}

So you get the idea. 所以你明白了。 Of course you can simply skip the $filter part and simply get list of all set names and cache them somewhere. 当然,您可以跳过$filter部分,只需获取所有设置名称的列表并将其缓存到某处。

1.To get all the entities available in your crm: 1.获取crm中的所有实体:

https://<your org name>.crm.dynamics.com/api/data/v8.2/

2.To get all the records metadata information (Retrieve Multiple Records): 2.获取所有记录元数据信息(检索多个记录):

https://<your org name>.crm.dynamics.com/api/data/v8.2/accounts?

3.To get the specific record email address information (Retrieve Single Record). 3.获取特定记录电子邮件地址信息(检索单个记录)。 What ever we chose the attributes in the select clause, we can get those attributes information in the result: 我们在select子句中选择了哪些属性,我们可以在结果中获取这些属性信息:

https://<your org name>.crm.dynamics.com/api/data/v8.2/accounts?$select=emailaddress1&$filter=accountid eq <GUID goes here>

4.To get entire metadata information in the CRM: 4.在CRM中获取整个元数据信息:

https://<your org name>.crm.dynamics.com/api/data/v8.2/EntityDefinitions

Another approach would be to generate the plural name from the singular name. 另一种方法是从单数名称生成复数名称。

As far as I understand, the rules to pluralize entity names in the Web API v8+ are: 据我所知,Web API v8 +中复数实体名称的规则是:

  • ends with s, x, z, ch, or sh: add 'es' 以s,x,z,ch或sh结尾:添加'es'
  • ends with y: remove 'y', add 'ies' 以y结尾:删除'y',添加'ies'
  • else: add 's' 否则:添加's'

Here is a JavaScript function that I use for this: 这是我用于此的JavaScript函数:

function pluralName (name) {
    var plural = '';
    if (name != null && typeof(name) == 'string') {
        var len = name.length;
        var lastChar = len > 0 ? name.slice(-1) : '';
        var last2Chars = len > 1 ? name.slice(-2) : '';

        if (lastChar == 's' || lastChar == 'x' || lastChar == 'z' || last2Chars == 'ch' || last2Chars == 'sh') {
            plural = name + 'es';
        }
        else if (lastChar == 'y') {
            //strip off last character and add suffix
            plural = name.substr(0, len - 1) + 'ies';
        }
        else {
            plural = name + 's';
        }
    }
    return plural;
}

Well, if you want the entities list, you can simply query and parser the root of the service like this: 好吧,如果你想要实体列表,你可以简单地查询和解析服务的根目录,如下所示:

https://contoso.api.crm.dynamics.com/api/data/v8.1/ https://contoso.api.crm.dynamics.com/api/data/v8.1/

If you want the fields too, you can do this: 如果你也想要这些字段,你可以这样做:

https://contoso.api.crm.dynamics.com/api/data/v8.1/ $metadata https://contoso.api.crm.dynamics.com/api/data/v8.1/ $ metadata

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

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