HI,
I have a lead from. Lead form has a field name customer(which is account entity). Account has a relationship with custom entity- Project.
Now i have a grid on lead form of project entity. Based on customer lookup, i need to filter the grid.
For which i have wrote a code java script but it is not working as expected.
P.S. Crm version 2016 update 1.
Code snippet:
function filterProjectGridOnCustomer()
{
debugger;
//var grid =Xrm.Page.ui.controls.get('PastProjects').control;
var grid =window.parent.document.getElementById('PastProjects');
//var grid=Xrm.Page.ui.controls.get('PastProjects');
var Grid=Xrm.Page.getControl('PastProjects');
Grid=Grid.getGrid();
var lookupfield = new Array;
//Get the lookup field
lookupfield = Xrm.Page.getAttribute('customerid').getValue();
if (lookupfield != null) {
var lookupid = lookupfield[0].id;
}
else {return;}
if (grid ==null){
/*This statement is used to wait for 2 seconds and recall the function until the grid is loaded.*/
setTimeout('filterProjectGridOnCustomer()', 2000);
return;
}
var fetchXMl = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>";
fetchXMl +="<entity name='msdyn_project'>";
fetchXMl +="<attribute name='msdyn_projectid' />";
fetchXMl +="<attribute name='msdyn_subject' />";
fetchXMl +="<attribute name='new_totalprojectcostcr' />";
fetchXMl +="<attribute name='new_outstandingamountcr' />";
fetchXMl +="<attribute name='new_location' />";
fetchXMl +="<attribute name='new_invoicecollectedcr' />";
fetchXMl +="<attribute name='new_invoicebilledcr' />";
fetchXMl +="<link-entity name='account' from='accountid' to='msdyn_customer' alias='ad'>";
fetchXMl +="<filter type='and'>";
fetchXMl +="<condition attribute='accountid' operator='eq' uiname=' ' uitype='account' value='"+lookupid +"' />";
fetchXMl +="</filter>";
fetchXMl +="</link-entity>";
fetchXMl +="</entity>";
fetchXMl +="</fetch>";
grid.control.SetParameter("fetchXml", fetchXMl );
grid.control.refresh();
}