I've N:N relationship between account and Relationship Type (A custom entity). Now on Recording entity (Another custom entity) I've an account lookup and I want to add presearch criteria so that the lookup can show only the specific that have 'Vendor' relation in relationship type. So far, I've following snippet to make the lookup presearch but it shows all records. I am not sure where I am doing wrong. Any Idea/suggestion?
function filterAccounts() {
try {
debugger;
var accountLookup = Xrm.Page.getControl("new_accountid");
if (accountLookup == null && accountLookup == 'undefined') { }
else {
accountLookup.addPreSearch(function () {
CustomFilter(accountLookup);
});
}
} catch (e) {
alert("Error: " + e.message);
}
}
function CustomFilter(accountLookup) {
try {
debugger;
var fetchXml = "<link-entity name='new_account_new_relationshiptype' from='accountid' to='accountid' visible='false' intersect='true'>" +
" <link-entity name='new_relationshiptype' from='new_relationshiptypeid' to='new_relationshiptypeid' alias='ak'>" +
" <filter type='and'>" +
" <condition attribute='new_name' operator='eq' value='Vendor' />" +
" </filter>" +
" </link-entity>" +
" </link-entity>";
accountLookup.addCustomFilter(fetchXml);
} catch (e) {
alert("Error: " + e.message);
}
}