Microsoft Dynamics CRM 2015 – Subgrid Lookup Filter 7


It make sense to filter both the sub grid and the lookup that is used to add new elements in the grid. The filter sub grid lookup then can allow to be displayed on the desired elements like in the image below:

CRM Subgrid filter

Microsoft CRM Subgrid filter custom

The Microsoft subgrid can be placed on a CRM page and, for 1:N relationship, the end user has the ability to add, delete and select the entries for this type of relationship. Any subgrid can be filtered with JavaScript for the data that are loaded with a custom fetchXML like in the example below:

 

However, how can we filter the lookup that is used to add existing records to the Microsoft CRM subgrid? The exiting data is correctly filtered but we want the end user to be able to select from the lookup only the records that are from the same filter as the filter of the subgird.

After inspecting the DOM structure of the subgrid and carefully understand the mechanics of the lookup filter it was discovered that the filter of the subgrid for CRM 2015 can be set like in the JavaScript below:

Are you using CRM 2013? Good news for you today! The code for CRM 2013 looks like this:

 

 


Leave a comment

Your email address will not be published. Required fields are marked *

7 thoughts on “Microsoft Dynamics CRM 2015 – Subgrid Lookup Filter

    • mike Post author

      This is a javascript chain properties path and it looks odd because is obfuscated by Microsoft team to protect their intellectual property on the javascript source code.
      In our projects we experienced different properties for different versions of CRM and different type of grids. For example for “Turbo SubGrid” the property is completely different. If this is your case then you have to search for where is “addPreSearch” callback function and yes it can take time until you find it. If this is critical for your business we recommend you to contact Bobylog Sales Department on http://www.bobylog.com/contact/ for a quotation and a CRM developer will be allocated to assist with your issue.

  • Michael Goriachev

    Hello/ thanks for saving a lot of time. but some functions like addEventListener or settimeout is not necessary. here is the good function:
    function FilterSubgridLookup() {
    var acc = Xrm.Page.getAttribute(“new_client”).getValue();
    if (acc == null) { return; }
    var filterXML = [
    ”,
    ”,

    ].join(‘\n’);
    var gridControl = Xrm.Page.getControl(“docs”);
    if (gridControl == null) {
    setTimeout(FilterSubgridLookup, 500); return;
    }
    if (gridControl.$c_0 == null || gridControl.$c_0.$N_4 == null || gridControl.$c_0.$N_4.$Y_3 == null) {
    setTimeout(FilterSubgridLookup, 500); return;
    }
    var me = gridControl.$c_0.$N_4.$Y_3;
    me.addPreSearch(function () {
    me.addCustomFilter(filterXML);
    });
    }

    • mike Post author

      In the solution proposed by Bobylog team, the function addEventListener is an event that listens when the buttons is clicked. When that button is clicked, the $c_0.$N_4.$Y_3 property gets created.
      From your solution, the event listener is replaced with a loop since setTimeout(FilterSubgridLookup, 500) is called every 500ms until the property gets created.
      Bobylog team does not recommend your implementation since a loop Timer will have a performance penalty on the browser CPU speed and memory allocation.
      For a better browser performance, please try to use as EVENTS as much as possible rather than replacing with TIMERS conditional loops.

  • Sieg Nguyen

    Hello,

    About $c_0.$N_4.$Y_3, my current MS CRM version is 7.0.2.53 (CRM 2015 Update 0.2). And I get error: “Error: Unable to get property ‘$Y_3’ of undefined or null reference”. Look likes $c_0.$N_4.$Y_3 is getting outdate in this version. Can you help me this point?