[英]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 中,未编码的点会导致转换错误。
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'];
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/
<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>
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.