function customfilterlookup(AccoundID)
{
//Show Contacts which has selected parent Account
//build fetchxml, use Advance Find to get Fetchxml
var viewId = "{a76b2c46-c28e-4e5e-9ddf-951b71202c9d}"; //view Guid
var entityName = "contact"; // Entity to be filtered
var viewDisplayName = "Active Contacts"; // Custom name for the lookup window.
var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
"<entity name='contact'>" +
"<attribute name='fullname' />" +
"<attribute name='parentcustomerid' />" +
"<attribute name='emailaddress1' />" +
"<attribute name='address1_telephone2' />" +
"<attribute name='new_city' />" +
"<attribute name='address1_stateorprovince' />" +
"<attribute name='address1_telephone1' />" +
"<attribute name='ownerid' />" +
"<attribute name='contactid' />" +
"<order attribute='fullname' descending='false' />" +
"<filter type='and'>" +
"<condition attribute='parentcustomerid' operator='eq' uitype='account' value='"+AccoundID+"' />" +
"<condition attribute='statecode' operator='eq' value='0' />" +
"</filter>" +
"</entity>" +
"</fetch>";
// Build Grid Layout. building a custom view for the Lookup
//building grid layout with the columns which needs to be displayed in the lookup view
var layoutXml = "<grid name='resultset' " +
"object='1' " +
"jump='name' " +
"select='1' " +
"icon='1' " +
"preview='1'>" +
"<row name='result' " +
"id='contactid'>" + // Id/key attribute of the entity to be filtered
"<cell name='fullname' " +
"width='250' />" +
"<cell name='new_city' " +
"width='70' />" +
"<cell name='address1_telephone1' " +
"width='100' />" +
"</row>" +
"</grid>";
// add new view to the lookup
Xrm.Page.getControl("contact").addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, true);
}