Good afternoon,
As the title suggests: within the Lead entity, I'm trying to filter on contacts so that when I find "Contact X", it will present me with their "Client" only. Because it's across multiple entities, I cannot use the .addPreSearch or .addCustomfilter. Instead, I'm having to create my own fetch XML and Custom View (code below).
I've added the function "FilterContact" on both the OnLoad and onChange of "ParentContactId".
function FilterContact() {
var ContactFilter = Xrm.Page.getAttribute("parentcontactid").getValue();
var viewId = GenerateGuid();
var entityName = "contact";
var viewDisplayName = "Account Filtered View Test";
var defaultViewId = Xrm.Page.getControl("parentaccountid").getDefaultView();
if (ContactFilter != null) {
var fetchXML = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'> " +
" <entity name='account'> " +
" <attribute name='name'/> " +
" <attribute name='accountid'/> " +
" <order attribute='name' descending='false'/> " +
" <link-entity name='contact' alias='ae' to='accountid' from='parentcustomerid' " +
" <filter type='and'> " +
" <condition attribute='contactid' operator='eq' value='" + ContactFilter + "'/> " +
" </filter>" +
" </link-entity>" +
" </entity>" +
" </fetch>";
var layoutXML = "<grid name='resultset'" +
" object='1'" +
" jump='accountid'" +
" select='1'" +
" icon='1'" +
" preview='1'>" +
" <row name='result'" +
" id='accountid'>" +
" <cell name='name'" +
" width='200'/>" +
" <cell name='accountid'" +
" width='200' />" +
" </row>" +
" </grid>";
Xrm.Page.getControl("parentaccountid").addCustomView(viewId, entityName, viewDisplayName, fetchXML, layoutXML, true);
alert ("test1");
}
else {
Xrm.Page.getControl("parentaccountid").setDefaultView(defaultViewId);
alert ("test2");
}
}
// Generate new Guid
function Hexa4() {
return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
}
function GenerateGuid() {
return ("{" + Hexa4() + Hexa4() + "-" + Hexa4() + "-" + Hexa4() + "-" + Hexa4() + "-" + Hexa4() + Hexa4() + Hexa4()).toUpperCase() + "}";
}
Does anyone have any suggestions? No errors are presented, but the filtered view is not shown.
Thanks in advance !