web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Blogs / DynamicsPeople / How to apply Filtering to l...

How to apply Filtering to lookup value

AbhiCode Profile Picture AbhiCode 492

Dear Dynamics People,

As many time we receive requirement that shows only some specifics data in the lookup field. In sub gird, we can create a view with specifics condition and shown in it. But for lookup view is always fix we cannot apply another view.

To achieve this requirement need to apply JavaScript to two function  addPreSearch and addCustomFilter

function FilteraccountList() {

var account = Xrm.Page.getAttribute("accountcustomer").getValue();

 if (account != null) {

var accountTextValue = account[0].name;
 var accountID = account[0].id;

Xrm.Page.getControl("accountcustomer").addPreSearch(function () {
 var account_filter = "<filter type='and'>" + "<condition attribute= 'number' operator='not-null' />" + "<condition attribute='code' operator='eq' value='287850000' />" +"<condition attribute='account' operator='eq' name='" + accountTextValue + "' value='" + accountID + "' />"+ "</filter>";


 Xrm.Page.getControl("accountcustomer").addCustomFilter(account_filter, "account");
 })

}

}

Apply this function to form onload and lookup filed onchange.

Thanks


This was originally posted here.

Comments

*This post is locked for comments