locked
Controlling SUBGRID on the basis of Lookup in CRM 2011 RRS feed

  • Question

  • Hi

    I have a  requirement where I need to select a record (which is a lookup to another entity) and the sub-grid below will only list the associated records attached to that lookup entity.

    For e.g: in 'Contract' entity form I have a sub-grid of 'servicelevel' entity (custom entity) and 'servicelevel' has many to one relation to 'Contracttemplate' so if in contract when I select a contract template it should list all the servicelevels associated to that contracttemplate.

    Basically i need to know how do I fetch the sub-grid contacts from lookup using Jscript ?

    Please help me out on this....

     

    Thanks

     

    Fayz


    Fkhoja
    Wednesday, January 25, 2012 3:27 PM

Answers

  • Hi,

    You can change the view of a subgrid dynamically using this (undocumented / potentially unsupported) JavaScript:

    var viewId = [view GUID];
    var viewType = 4230; // personal view (userquery)
    // var viewType = 1039; // system view (savedquery)
    
    var subgrid = document.getElementById('your_subgrid');
    subgrid.control.setParameter('viewid', viewId);
    subgrid.control.setParameter('viewtype', viewType);
    subgrid.control.refresh();
    

    From here, you have the issue of filtering the view dependant on selected contract template. You could manually create a view for each contract template to display the service level records or automate this using a workflow or plugin when a new contract template is created. From here, when your lookup is changed on the contract you can query for the view ID using the CRM web service and update the subgrid.

    Another option is to dynamically generate the FetchXML query to populate your view based on the selected contract template lookup and pass this through to the subgrid using a similar method:

     

    var fetchXml = '[generate your FetchXML query]';
    
    var subgrid = document.getElementById('your_subgrid');
    subgrid.control.setParameter('fetchxml', fetchXml);
    subgrid.control.refresh();
    

    This will give you more control and will only use JavaScript, but you have to go through the process of generating your dynamic FetchXML query to populate the subgrid.

    Note you can also use subgrid.control.getParameter('parameterName') to get the value of specific parameters, like the current view ID/type, FetchXML query or the columns defined in the LayoutXML:

    var subgrid = document.getElementById('your_subgrid');
    alert(subgrid.control.getParameter('viewid'));
    alert(subgrid.control.getParameter('viewtype'));
    
    alert(subgrid.control.getParameter('fetchxml'));
    alert(subgrid.control.getParameter('layoutxml'));
    

    Are these workable solutions for you? Let me know if you have any other questions.

     

    Cheers,

    Tully

    • Marked as answer by Fkhoja Wednesday, February 8, 2012 12:21 PM
    Tuesday, January 31, 2012 10:41 PM