How to apply Filtering to lookup value

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.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s