I have to filter records on a link entity, I have build the fetch XML which is working fine in XRM Tool Box fetch XML builder. But the same fetch XML is not working in the Power Pages portal.
Here is my code
var testFetchXML = `
<fetch version="1.0" mapping="logical" output-format="xml-platform" distinct="true">
<entity name="tgm_notification">
<attribute name="tgm_notificationid" />
<attribute name="tgm_title" />
<attribute name="tgm_message" />
<attribute name="tgm_type" />
<attribute name="tgm_targetaudience" />
<attribute name="tgm_targetaccount" />
<attribute name="tgm_targetrole" />
<attribute name="tgm_publishedfrom" />
<attribute name="tgm_publishedto" />
<attribute name="createdon" />
<order attribute="createdon" descending="true" />
<filter type="and">
<condition attribute="statecode" operator="eq" value="0" />
<link-entity name="tgm_notificationstatustracker" from="tgm_notification" to="tgm_notificationid" link-type="not all">
<filter>
<condition attribute="tgm_contact" operator="eq" value="67cf586a-afd9-eb11-bacb-000d3abc2473" uitype="contact" />
</filter>
</link-entity>
</filter>
</entity>
</fetch>`
var uri = `/_api/tgm_notifications?fetchXml=${encodeURIComponent(testFetchXML)}`;
$.ajax({
type: "GET", url: uri, contentType: "application/json", async: false,
success: function (spData) {
console.log(spData)
},
error: function (xhr) {
console.error("Error", xhr);
}
});
Both tables: notification and notificationstatustracker have the read permissions. Also, I am already getting the data, it's just that the link-entity filter is somehow not working in the request made from portal. Also, the contactid used in fetch XML is correct since the same filter is working fine in XRM Tool box.
Any help would be appreciated. Let me know if any more information is required.
I ran into a similar issue (although I was using fetchxml through liquid, rather than using the API). It seems Power Pages appends all the table permissions as extra link-entities to any fetchxml queries that are sent to dataverse.
For any tables that are also used in your table permissions, try giving those link-entities an alias and see if that helps.
This blog post was helpful for me. In liquid, you can view the full query that is being sent using the .xml attribute (details in the post). If there's an equivalent for the api you could try that, too.