有没有办法绕过返回的fetchXML值返回正确的链接实体逻辑名称命名,而不是构建命名,如:
customer_contact1_x002e_contactid
customer_contact1_x002e_fullname
我从请求中删除了所有别名。它是什么东西,不能在请求中修复?或者它是由Microsoft CRM推出的用于指定实体关系的“尾巴”,我所能做的就是在响应中使用它?
_x002e_
表示将前缀与属性名称分开的点(。)。 (这是十六进制形式的字符代码。)在JSON中,未编码的点会导致转换错误。
您可以考虑使用JSON reviver函数将十六进制代码转换为任何文本。 (见MDN。)
正如@Henk van Boeijen所说:
_x002e_
表示将前缀与属性名称分开的点(。)。 (这是十六进制形式的字符代码。)在JSON中,未编码的点会导致转换错误。
处理此问题的最简单方法是仅对实体名称(别名),十六进制点和属性名称进行硬编码。然后将它们连接在一起。
obj['myopportunityalias'+ '_x002e_' + 'closeprobability'];
此示例显示如何重新映射已解析对象的属性。即使对于这种方法,也需要通过连接如上所示的三个部分来确定原始属性。因此,我认为这样做没有任何好处。
另一种方法是使用与此类似的正则表达式检查属性:/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]);
在当天晚些时候,但我发现这篇文章正在寻找这个问题的答案。
实际上有一种非常简单的方法来处理它而不是开发一个复活者。如果在FetchXML中为属性设置别名,则将从结果中删除点符号,并且可以直接通过别名引用结果列。以下命令返回当前用户创建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>`
产生结果:
[{
roleid: "b2d0dc99-81cf-e711-9669-00155d0e5f01",
privdepth: 8
}}