简体   繁体   English

Dynamics CRM web api FetchXml 返回带有“2_x002e_”的链接实体命名,两者之间类似

[英]Dynamics CRM web api FetchXml returns linked Entities naming with '2_x002e_' and similar in between

Is there any way to bypass that returned values of fetchXML returns correct naming of linked entity logical name, not build naming, like :有什么方法可以绕过 fetchXML 的返回值返回链接实体逻辑名称的正确命名,而不是构建命名,例如:

customer_contact1_x002e_contactid
customer_contact1_x002e_fullname  

I removed all aliases from requests.我从请求中删除了所有别名。 Is it something, that can not be fixed in request?有什么不能在请求中修复的吗? Or is it a 'tail' putted by Microsoft CRM to specify entities relationships and all I can do is to work with that in response?或者它是 Microsoft CRM 用来指定实体关系的“尾巴”,而我所能做的就是使用它作为响应?

The _x002e_ represents the dot (.) which separates the prefix from the attribute name. _x002e_表示将前缀与属性名称分开的点 (.)。 (It's the character code in hexadecimal form.) In JSON the unencoded dot would lead to conversion errors. (它是十六进制形式的字符代码。)在 JSON 中,未编码的点会导致转换错误。

You could consider to convert the hex code to any text using a JSON reviver function.您可以考虑使用 JSON reviver 函数将十六进制代码转换为任何文本。 (See MDN .) (见MDN 。)

As @Henk van Boeijen stated already correctly:正如@Henk van Boeijen 已经正确指出的那样:

The _x002e_ represents the dot (.) which separates the prefix from the attribute name. _x002e_表示将前缀与属性名称分开的点 (.)。 (It's the character code in hexadecimal form.) In JSON the unencoded dot would lead to conversion errors. (它是十六进制形式的字符代码。)在 JSON 中,未编码的点会导致转换错误。

TL;DR TL; 博士

The easiest way to handle this is to just hardcode the entityname (alias), the hexadecimal dot and the attribute name.处理此问题的最简单方法是对实体名称(别名)、十六进制点和属性名称进行硬编码。 Then concatenate them all together.然后将它们连接在一起。

obj['myopportunityalias'+ '_x002e_' + 'closeprobability'];

Example示例

This example shows how to remap the properties of the parsed object.此示例显示如何重新映射已解析对象的属性。 Even for this approach it is needed to determine the original property by concatenating the three parts as seen above.即使对于这种方法,也需要通过连接如上所示的三个部分来确定原始属性。 Therefore, I do not see any benefit in doing so.因此,我认为这样做没有任何好处。

Another approach would be to check the properties with a regular expression similar to this: /entityalias_.+_attributename/另一种方法是使用类似于以下的正则表达式检查属性:/ /entityalias_.+_attributename/

FetchXML获取XML

    <fetch>
      <entity name="account" >
        <attribute name="name" />
        <link-entity name="opportunity" from="parentaccountid" 
             to="accountid" link-type="outer" alias="myopportunityalias" >
          <attribute name="closeprobability" />
        </link-entity>
      </entity>
    </fetch>

JS JS

 var json = '{"account": "Contoso", "myopportunityalias_x002e_closeprobability": 99 }'; obj = JSON.parse(json); var alias = 'myopportunityalias' var attribute = 'closeprobability' var fullKey = alias + '_x002e_' + attribute; console.log(obj[alias + '_x002e_' + attribute]); // just concatenate or hardcode it var newObj = {}; for (var prop in obj) { if (obj.hasOwnProperty(fullKey)) { obj[alias + attribute] = obj[fullKey]; delete obj[fullKey]; } } console.log(obj.myopportunityaliascloseprobability); console.log(obj[alias + attribute]);

Bit late in the day but I found this article looking for an answer to this problem.当天有点晚,但我发现这篇文章正在寻找这个问题的答案。

There's actually a very easy way to deal with it rather than developing a reviver.实际上有一个非常简单的方法来处理它,而不是开发一个复活者。 If you alias your attributes in the FetchXML, you'll remove the dot notation from the results and you can reference the result's column directly through the alias name.如果您在 FetchXML 中为您的属性设置别名,您将从结果中删除点表示法,您可以通过别名直接引用结果的列。 The following returns the depth of privilege for the current user for Creating Notes.下面返回当前用户创建 Notes 的权限深度。

<fetch>
  <entity name='role' >
    <link-entity name='systemuserroles' from='roleid' to='roleid' alias='userroles' intersect='true' >
      <filter>
        <condition attribute='systemuserid' operator='eq-userid' />
      </filter>
    </link-entity>
    <link-entity name='roleprivileges' from='roleid' to='roleid' intersect='true' >
      <attribute name='privilegedepthmask'  alias='privdepth' />
      <link-entity name='privilege' from='privilegeid' to='privilegeid'>
        <filter>
          <condition attribute='name' operator='eq' value='prvCreateNote' />
        </filter>
      </link-entity>
    </link-entity>
  </entity>
</fetch>`

Yields the result:产生结果:

[{ 
    roleid: "b2d0dc99-81cf-e711-9669-00155d0e5f01", 
    privdepth: 8 
}}

暂无
暂无

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

相关问题 动态CRM。 在subgrid中完全自定义FetchXml - Dynamics CRM. Fully custom FetchXml in subgrid 动态CRM 2016-Web API查询-动态值 - dynamics crm 2016 - Web API query- dynamic values Dynamics CRM web api 8.2“分页 Cookie 中的格式错误的 XML” - Dynamics CRM web api 8.2 'Malformed XML in the Paging Cookie' 我们如何在js中识别Dynamics CRM Web api版本? - How can we identify the Dynamics CRM web api version in js? 来自外部站点的Dynamics CRM Web API(JavaScript) - Dynamics CRM Web API from external site (javascript) FetchXML查询在子网格中返回的Dynamics CRM 2015中的活动记录-主题超链接打开新的活动 - Activity records in Dynamics CRM 2015 returned in subgrid by FetchXML query - Subject hyperlink opens new Activity 使用调用 HTTPRequest 的 FetchXml 查询检索 CRM Dynamics 365 版本 8.2 中的多条记录,但 HTTPRequest 将不起作用 - Retrieve multiple records in CRM Dynamics 365 version 8.2 using FetchXml query calling HTTPRequest but HTTPRequest will not work 将Dynamics CRM Web API直接消费到Django Web应用程序中的PostgreSQL数据库中 - Consume Dynamics CRM Web API directly into PostgreSQL database in Django web app 设置子网格的fetchXML时,无法读取Dynamics CRM中未定义的属性“ SetParameter” - Cannot read property 'SetParameter' of undefined in Dynamics CRM while setting up fetchXML of a subgrid Dynamics CRM - JS ReferenceError“X”未定义 - Dynamics CRM - JS ReferenceError "X" is not defined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM