Forums

Forums / Developing Portals / Grid fetchXML aggregate or link-type='matchfirstrowusingcrossapply' issues

Grid fetchXML aggregate or link-type='matchfirstrowusingcrossapply' issues

5 posts, 0 answered
  1. Dmitriy Razumov
    Dmitriy Razumov avatar
    3 posts
    Registered:
    09 Aug 2024
    09 Aug 2024
    Link to this post
    Hello,

    we're having a problem making a query inside a grid. We're making link-entity not to get any attributes from it, but only for applying filters. There are more than one linked records, which results in duplicates in the grid.

    Distinct=true doesn't work because TPC automatically includes primary Id for linked records making duplicates distinct. We solved it by applying aggregate fetch, but with aggregate fetch Sorting by columns on the front end is not working, because TPC code probably adds order by attribute, but aggregate requires every attribute to have alias and it results in error "An attribute cannot be specified for an order clause for an aggregate query. Use an alias".

    Then we tried link-type='matchfirstrowusingcrossapply'

    https://learn.microsoft.com/en-us/power-apps/developer/data-platform/fetchxml/join-tables?tabs=fetchxml#use-matchfirstrowusingcrossapply-link-type

    it works fine if I make request outside TPC (in XrmToolbox FetchXML builder), but TPC grid ignores this instruction which again results in duplicates.

    Also, we tried intersect=true with the same result

    https://learn.microsoft.com/en-us/power-apps/developer/data-platform/fetchxml/join-tables?tabs=fetchxml#many-to-many-relationships

    Could you please tell us what can we do? Is there some flag to use Raw FetchXML in the Grid Model Settings? Or to disable auto-include of linked records Primary Id? Or Is there some event on the server side where I can modify the FetchXML request that's being sent to Dynamics? Or if there's some flag to use aliases instead of attributes for ordering?

    Tnank you.
  2. Craig Furlonger
    Craig Furlonger avatar
    8 posts
    Registered:
    12 Aug 2024
    12 Aug 2024 in reply to Dmitriy Razumov
    Link to this post
    Hi Dmitry,

    While there are features in XRMToolBox that are not directly supported in TPC Fetch, if you copy and paste the fetch from XRMToolBox into TPC Fetch it should still work. Is that what you're doing?
  3. Dmitriy Razumov
    Dmitriy Razumov avatar
    3 posts
    Registered:
    09 Aug 2024
    13 Aug 2024 in reply to Craig Furlonger
    Link to this post
    Hello, Craig,

    Yes, that's exactly what I'm doing, copying FetchXML directly, but unfortunately looks like TPC ignores link-type='matchfirstrowusingcrossapply'
    https://learn.microsoft.com/en-us/power-apps/developer/data-platform/fetchxml/join-tables?tabs=fetchxml#use-matchfirstrowusingcrossapply-link-type
  4. Craig Furlonger
    Craig Furlonger avatar
    8 posts
    Registered:
    12 Aug 2024
    13 Aug 2024 in reply to Dmitriy Razumov
    Link to this post
    Can you share the fetch that you're using?
  5. Dmitriy Razumov
    Dmitriy Razumov avatar
    3 posts
    Registered:
    09 Aug 2024
    14 Aug 2024 in reply to Craig Furlonger
    Link to this post
    Sure,

    <fetch>
      <entity name="contact">
        <attribute name="contactid" />
        <attribute name="fullname" />
        <link-entity name="connection" to="contactid" from="record2id" link-type="matchfirstrowusingcrossapply">
          <attribute name="connectionid" />
          <filter type="and">
            <condition attribute="statecode" operator="eq" value="0" />
            <condition attribute="record1id" operator="eq" value="f45643b5-2ee0-e911-a812-000d3af4363f" />
          </filter>
          <filter type="or">
            <condition attribute="record2roleid" operator="eq" value="E6B08E00-3309-E811-8135-480FCFF475A1" />
            <condition attribute="record2roleid" operator="eq" value="B60F975B-FF44-E811-813A-480FCFE9CF31" />
          </filter>
        </link-entity>
      </entity>
    </fetch>


    In FetchXML Builder it returns no duplicate contacts (it the have more than one connection) because of link-type="matchfirstrowusingcrossapply", in TPC it returns duplicates ignoring link-type="matchfirstrowusingcrossapply"

    TPC version is v6.2.144.104
5 posts, 0 answered