admin管理员组文章数量:1401314
Is there any way to bypass that returned values of fetchXML returns correct naming of linked entity logical name, not build naming, like :
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?
Is there any way to bypass that returned values of fetchXML returns correct naming of linked entity logical name, not build naming, like :
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?
Share Improve this question edited Dec 13, 2019 at 15:16 Arun Vinoth PrecogTechnologies 22.8k17 gold badges62 silver badges180 bronze badges asked Jul 20, 2017 at 6:21 raichiksraichiks 2864 silver badges16 bronze badges 2- Hello and wele to Stack Overflow, please take a time to go through the wele tour to know your way around here (and also to earn your first badge), read how to create a minimal reproducible example example and also check How to Ask so you increase your chances to get feedback and useful answers. – garfbradaz Commented Jul 20, 2017 at 6:22
- Hello. many thanks for advice. I will check that, to upgrade my question asking skills. – raichiks Commented Jul 20, 2017 at 6:29
3 Answers
Reset to default 7The _x002e_
represents the dot (.) which separates the prefix from the attribute name. (It's the character code in hexadecimal form.) In JSON the unencoded dot would lead to conversion errors.
You could consider to convert the hex code to any text using a JSON reviver function. (See MDN.)
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. The following returns the depth of privilege for the current user for Creating 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
}}
As @Henk van Boeijen stated already correctly:
The
_x002e_
represents the dot (.) which separates the prefix from the attribute name. (It's the character code in hexadecimal form.) In JSON the unencoded dot would lead to conversion errors.
TL;DR
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/
FetchXML
<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
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]);
本文标签:
版权声明:本文标题:javascript - Dynamics CRM web api FetchXml returns linked Entities naming with '2_x002e_' and similar in between 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744244317a2596936.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论