Customize Customer Lookup to show only Accounts or Contacts

Hi,
 
In some projects we may need customize the Customer look up on Case, Opportunity etc.. for showing only Accounts or Contacts based on some conditions.
 
We can achieve this using addPreSearch and addCustomFilter in JavaScript. Let us see this now.

I have taken Case entity here.

By default, Customer Look up shows Accounts and Contacts.

Accounts

Contacts


Let us customize it by writing some JavaScript code. The method is called on the load event, you can use it based on your requirement.

Here is the JavaScript code

function OnLoad() {
    addEventHandler();
}
 
function addEventHandler() {
    Xrm.Page.getControl(“customerid”).addPreSearch(addFilterToShowContacts);
    //Xrm.Page.getControl(“customerid”).addPreSearch(addFilterToShowAccounts);
}
 
// For showing only Contacts.
function addFilterToShowContacts() {
    var account_filter = “” +
     “” +
    “”;
    Xrm.Page.getControl(“customerid”).addCustomFilter(account_filter, “account”);
}
 
// For showing only accounts.
function addFilterToShowAccounts() {
    var account_filter = “” +
    “” +
    “”;
    Xrm.Page.getControl(“customerid”).addCustomFilter(account_filter, “contact”);
}
Showing Only Contacts

Showing Only Accounts



The only problem I see in this approach is User has select the dropdown(Account/Contact) but this is only supported way we have. Let’s hope next versions of CRM will give some other technique to solve it for us.

Hope this helps.

Happy CRM’ing
Gopinath.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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