Posted in Code Snippets, CRM, JavaScripts, XML

LookUp Filtering Using form Value By Javscript

Filtered LookUp  Using form Value By Javscript :-

Contact entity has the lookup of account entity. The Account lookup must show the related Email Accounts based on email of contact entity. Before entering the email value on contact entity, It will show all the accounts and once if he entered the email it have to show the only related email accounts.

Trigger the following function EmailPreFilterLookup()  on ONLOAD of form.

addPreSearch method will trigger when we click on the Account LookupFiled Icon 45

 

function EmailPreFilterLookup() {
 Xrm.Page.getControl("AccountLookupschemaname").addPreSearch(function () {
 addLookupFilter();
 });
}
function addLookupFilter() {
debugger;
 var email = Xrm.Page.getAttribute("emailaddress1").getValue();
 if (email != null) {
 fetchXml = "<filter type='and'><condition attribute='emailaddress1' operator='eq' value='" + email + "' /></filter>";
 Xrm.Page.getControl("parentaccountid").addCustomFilter(fetchXml);
 }
}

 

Enjoy 🙂

Advertisements