Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 82002

fetchXml with Linked Entities on a Subgrid unable to find link-entity

$
0
0

Hello community,

I'm having issues with implementing an advanced filter on a Subgrid (entity 'email', shown on a 'contact' form as the subgrid 'emailGrid').

What I'd like to do is show all e-mails that contain the emailaddress1 of the current contact record, even if it's related to the systemuser of the same person. 

To do so I've built a fetchXml query in the FetchXML Builder:

<fetch mapping='logical' ><entity name='email' ><attribute name='to' /><attribute name='sender' /><attribute name='cc' /><attribute name='subject' /><attribute name='senton' /><filter type='or' ><condition entityname='contact' attribute='emailaddress1' operator='eq' value='test@kramerundcrew.de' /><condition entityname='systemuser' attribute='internalemailaddress' operator='eq' value='test@kramerundcrew.de' /></filter><order attribute='senton' descending='true' /><link-entity name='activityparty' from='activityid' to='activityid' link-type='outer' alias='party' ><link-entity name='contact' from='contactid' to='partyid' link-type='outer' alias='contact' ><attribute name='emailaddress1' /></link-entity><link-entity name='systemuser' from='systemuserid' to='partyid' link-type='outer' alias='systemuser' ><attribute name='internalemailaddress' /></link-entity></link-entity></entity></fetch>

However, I'm facing two issues with that query that I hope someone will be able to help me with:

a) When I add this to the subgrid, the grid itself tells me that "Link entity with name or alias contact is not found". I've tried using different alias (eg "ac" for the contact, "asu" for the systemuser) to no avail. The query works perfectly fine (aside from not being able to enable 'distinct' and therefore showing duplicate records) from within FetchXML Builder.

function updateSubGrid(executionContext) {
    var formContext =  executionContext.getFormContext();
    //var mailGrid = document.getElementById("emailGrid");
    //var mailGrid = window.parent.document.getElementById("emailGrid");
    var mailGrid = formContext.getControl("emailGrid");
    if (mailGrid == null) {
        console.log("mailGrid does not exist, retry in 1s.");
        setTimeout(function () { updateSubGrid(executionContext); },1000); // wait a second for the grid to load, then retry
        return;
    }
    var emailAddress = formContext.getAttribute("emailaddress1").getValue();
    console.log("set filter to emails from/to this email: "+emailAddress);
    if (emailAddress == null) return;
    var fetchXml = ""+"<fetch mapping='logical'>"+"<entity name='email' >"+
        // Columns to retrieve"<attribute name='to' />"+"<attribute name='sender' />"+"<attribute name='cc' />"+"<attribute name='subject' />"+"<attribute name='senton' />"+
        // Filter based on emailAddress through both linked entities"<filter type='or' >"+"<condition entityname='party.contact' attribute='emailaddress1' operator='eq' value='"+emailAddress+"' />"+"<condition entityname='party.systemuser' attribute='internalemailaddress' operator='eq' value='"+emailAddress+"' />"+"</filter>"+
            // Order by sent date"<order attribute='senton' descending='true' />"+
            // Link to activityparty"<link-entity name='activityparty' from='activityid' to='activityid' link-type='outer' alias='party' >"+
                // and link to Contact and Systemuser "<link-entity name='contact' from='contactid' to='partyid' link-type='outer' alias='contact' >"+"<attribute name='emailaddress1' />"+"</link-entity>"+"<link-entity name='systemuser' from='systemuserid' to='partyid' link-type='outer' alias='systemuser' >"+"<attribute name='internalemailaddress' />"+"</link-entity>"+"</link-entity>"+"</entity>"+"</fetch>";
    console.log(fetchXml);
    mailGrid._gridControl.setFilterXml(fetchXml);
    console.log("filter was set, refreshing grid.");
    mailGrid._gridControl.refresh();
}

b) When I try adding distinct='true' to the query, FetchXML Builder tells me "An unexpected error occured." without telling me what kind of error, then offers to try as ExecuteFetch, which DOES work.


Viewing all articles
Browse latest Browse all 82002

Latest Images

Trending Articles



Latest Images