Saturday, 19 April 2014

How to filter lookup in crm 2013

How filter lookup in CRM 2013.

Hello CRM Lovers,
   After release of CRM 2013 we got many new features in CRM. First is that performance increases of crm. There are various changes in java script functions for increasing performance of crm.

   Here is my new post with the new java scripts in crm 2013 for filtering lookup. In CRM 2013 there are many new functions for filtering like prefilter, removePrefilter etc. In this post I am going to describe how to use these functions.These functions will also increase performance of crm form.

Here is all about new lookup controls,s methos and events :- 

1. Method : addCustomFilter()  :-  

This function is new in crm 2013. It works as an additional filter to result displayed in lookup dialog each previous filter added with an AND condition to display result in lookup dialog. 

Note :-  
  • This method is only available for updated entities in crm 2013.
  • This method can only be used in a function in an event handler for the Lookup Control PreSearch Event.

      Xrm.Page.getControl("attributename").addCustomFilter(filter, entityLogicaName);
      Here filter is fetch xml for results and entityLogicalName 
      is name of the entity. 
      Example :-         
             <filter type="and">
               <condition attribute="name" operator="eq" value="Test" />

2. How to add custom view on lookup control :- 

Method : addCustomView():- This method is used to add custom view on  the lookup control.

Note :- This method does not work on "Owner" lookup. 

      Xrm.Page.getControl("attributename").addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, isDefault);

    Where :-
            viewId :- unique guid of format “{00000000-0000-0000-0000-000000000001}”.
    entityName :- Name of the entity of type "string".
    viewDisplayName :- Name of the view(Your custom name)of type "string".
    fetchXml :- fetch for retrieve data of type "string".
    layoutXml :- layout xml is for showing the records in a format as you want of type "string".
    isDefault :- Do you want this view as default of type "bool".


3. How to get default view of CRM lookup control :-

      var attrParent = Xrm.Page.getControl("attributename").getDefaultView();

    Returns the Id of the default view of the lookup dialog in 

4. How to set default view of CRM lookup control :-


              Where :-
      viewGuid :- Guid of the view.
          Set,s the default view in lookup dialog .

5. How to add or remove lookup control PreSearchEvent :-    

         This is new functionality in CRM 2013. Lookup PreSearchEvent just occurs just before the lookup dialog opens. Like other form and control events crm form editor does not peovide a way to add PresSerachEvent.This event can be used with other lookup methods like addCustomView, addCustomFilter etc.

Note :- These events only available for all custom entities in crm 2013 and these system entities :- Account,  Appointment, Campaign, Campaign Activity,Campaign Response,Case,Competitor,Contact,  Contract,Contract Line,Email,Fax,Invoice,Lead,Letter,Marketing List,Opportunity,Opportunity,  Product,Order,Phone Call,Price List Item,Product,Quick Campaign,Quote,Recurring Appointment, Sales Literature,Team,Task,User. 

      Where :-      
      functionName:- is the name of the function which you want to 
                     call before lookup, launch dialog.

      Where :-      
      functionName:- is the name of the function which you want to remove.

Enjoy the great technology Dynamics CRM. Good luck.

No comments: