Is that possible to make cast field in fetchxml?

柔情痞子 提交于 2019-12-01 21:28:23

I don't know if I am missing something, but Dynamics CRM/365 is quite forgiving when it comes to joining types. It is quite possible to join a string field to a guid field. See this sample, where I have placed a guid of an account in the fax attribute of a contact:

<fetch version='1.0' output-format='xml-platform' mapping='logical' >
  <entity name='contact' >
    <attribute name='fullname' />
    <attribute name='fax' />
    <attribute name='parentcustomerid' />
    <filter type='and' >
      <condition attribute='statecode' operator='eq' value='0' />
    </filter>
    <attribute name='contactid' />
    <link-entity name='account' from='accountid' to='fax' link-type='outer' >
      <attribute name='name' />
    </link-entity>
  </entity>
</fetch>

So yes, you are correct that casting is not possible, but the query in your example still executes nicely, which I guess was the goal of it all.

Casting is not possible in fetchxml. (Am unable to test this right away.)

Link entity join the 2 entities on Key GUIDs (Primary & Foreign Keys), it's better to create the relationship to maintain Database design & query them.

Interestingly, MSDN is saying Id as string in schema:

<!--

link-entity element - used for joining one entity to its "parent"

-->
  <!-- [XDR-XSD] "link-entity" element  -->
  <xs:complexType name="FetchLinkEntityType">
    <xs:choice minOccurs="0"
               maxOccurs="unbounded">
      <!-- -->
      <xs:element ref="all-attributes"
                  minOccurs="0" />
      <xs:element name="attribute"
                  type="FetchAttributeType"
                  minOccurs="0"
                  maxOccurs="unbounded" />
      <xs:element name="order"
                  type="FetchOrderType"
                  minOccurs="0"
                  maxOccurs="1" />
      <xs:element ref="filter"
                  minOccurs="0" />
      <xs:element name="link-entity"
                  type="FetchLinkEntityType" />
    </xs:choice>
    <!-- -->
    <xs:attribute name="name"
                  use="required"
                  type="xs:string"></xs:attribute>
    <xs:attribute name="to"
                  type="xs:string"></xs:attribute>
    <xs:attribute name="from"
                  type="xs:string"></xs:attribute>
    <xs:attribute name="alias"
                  type="xs:string"></xs:attribute>
    <xs:attribute name="link-type"
                  type="xs:string"></xs:attribute>
    <xs:attribute name="visible"
                  type="xs:boolean"></xs:attribute>
    <xs:attribute name="intersect"
                  type="xs:boolean"></xs:attribute>
  </xs:complexType>

Update:

Natively, fetchxml uses the guid keys to join (ex. From Advanced find). But it seems we can override that from and to with any field. It’s working as of today, Probably undocumented henceforth unsupported.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!