Quantcast
Channel: Microsoft Dynamics 365 Community
Viewing all articles
Browse latest Browse all 64797

Restrict customer lookup to select a specific entity records in CRM 2013/2015

$
0
0
A few years ago, I wrote a blog addCustomFilter method for lookup control in CRM2013.  Some of the readers asked the question that if “addCustomFilter” can be used to restrict/default the customer lookup to a specific entity. The answer to the question is that you can restrict the customer lookup to return the results for a specific entity but you can’t default it to the contact entity.
Here is an example on how to restrict the customer lookup on case entity to display contact records. I am using the same code that I have used in my original blog with a few changes.

Code

 function addEventHandler() {  
// add the event handler for PreSearch Event
Xrm.Page.getControl("customerid").addPreSearch(addFilter);
}
function addFilter() {
//create a filter xml
var filter ="<filter type='and'>" +
"<condition attribute='accountid' operator='null'/>" +
"</filter>";
//apply the filter
Xrm.Page.getControl("customerid").addCustomFilter(filter,"account");
}


In the above code, I am using the filter where accountid is null and applying it to the account entity. Account record will always has accountid therefore no account records will be returned.

Results

The following screen shot display the customer lookup returning only contact records.
image

If the user clicks on the “Look Up More Records”, CRM will display the following screen.
image

The customer lookup does not return any account records as shown in the screen shot above.
The user can change the “Look for” entity to contact and choose the contact record.

.....

Viewing all articles
Browse latest Browse all 64797

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>