addPreSearch and addCustomFilter in CRM 2013

Using these new methods we can now easily filter the lookup in CRM 2013.

Using addPreSearch we can specify a handler to PreSearch Event. Inside the handler we can specify our fetch xml query that can be used for filtering. The filter applied in the fetch xml will be combined with the any previously added filter as an 'AND' condition.

To remove the filter we can use removePreSearch method.

Here we are filtering the primary contact lookup to show only those records starting with S in the account form.

Account Form Load:-

The filter applies to all the Views.

Active Contacts View


Contacts: No Campaign Activities in Last 3 Month View


Shraddha Dhingra

Comments (5)

  1. pissed says:

    Neo you piggy back rider. Cheap ***.

  2. Munavvar says:

    Please provide an example of addPreSearch with removePreSearch.

    I am unable to remove the PreSearch.

  3. Linux says:

    That filter is lost when the subgrid is refreshed, again very good job of Microsoft.

  4. Nikki says:

    Hi ,

    I want to use filter-fetch  records which has a same parent purchase id ..

    so for that i am using your code.

    function addEventHandler() {    



    function addFilter() {

       var name = Xrm.Page.getAttribute('new_potitle').getValue();  

       var filter = "<filter type='and'>" +                

                    "<condition attribute='new_parent_poid' operator='eq'  value='" + name + "' />" +




    "pop_147" is subgrid control ..?is it correct or which field i have to replace for that?

    Please correct me.

Skip to main content