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
Add a ment  | 

3 Answers 3

Reset to default 7

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.

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]);

本文标签: