locked
CRM 2011 post-Rollup 12 Subgrid fetchXml RRS feed

  • Question

  • Since .readyState and .setParameter methods are deprecated for Rollup 12 (DOM access), is there a way to filter custom fetchXml to a subgrid?
    • Edited by wikky2007 Wednesday, July 10, 2013 10:31 PM
    Wednesday, July 10, 2013 10:31 PM

Answers

  • Guido,

    I am already getting the subgrid with:

    var relatedEducation = Xrm.Page.getControl("education_subgrid");

    The code you are referencing will not work in Update Rollup 12 and up.  Directly accessing the DOM is not supported.  I need to know if it is possible to inject custom fetchxml into a subgrid after Rollup 12.  Do you know of any other methods?  Thanks

    There isn't a supported way to change the fetchXml of a subgrid.
    The only way is to manipulate the DOM directly by using unsupported javascript. You are right that document.getElementById is not supported, but this doesn't mean that will not work, is up to you to maintain your code when a new release break something (as rollup12 update).
    To summarize:
    To change the FetchXml you need to get the control by using document.getElementById("");
    To refresh the subgrid you can use the supported method: Xrm.Page.getControl("").refresh;

    My blog: www.crmanswers.net

    • Proposed as answer by Guido PreiteMVP Friday, July 12, 2013 6:02 AM
    • Marked as answer by wikky2007 Thursday, September 5, 2013 3:10 PM
    Friday, July 12, 2013 6:01 AM

All replies

  • you just need to use SetParameter instead of setParameter 

    grid.control.SetParameter("fetchXml", fetchXml);



    My blog: www.crmanswers.net

    • Proposed as answer by Guido PreiteMVP Thursday, July 11, 2013 8:05 AM
    • Unproposed as answer by wikky2007 Thursday, July 11, 2013 12:41 PM
    Wednesday, July 10, 2013 10:38 PM
  • I tried that, but it didn't work.  What could possibly be wrong with this code?  I am calling the function in the OnLoad event and I am using Chrome for my browser:

    //  Load related Education records  
    function loadRelatedEducation() {
        var relatedEducation = Xrm.Page.getControl("education_subgrid");
        var lookupfield = new Array;
        lookupfield = Xrm.Page.getAttribute("new_contactid").getValue();
    
        if (lookupfield != null) { var lookupid = lookupfield[0].id; }
        else { return; }
    
        if (relatedEducation == null || relatedEducation.readyState != "complete") { setTimeout('loadRelatedEducation()', 2000); return; }
    
        var fetchXml =
        "<fetch distinct='false' mapping='logical' output-format='xml-platform' version='1.0'>" +
        "<entity name='new_education'>" +
        "<attribute name='new_name'/><attribute name='new_fieldofstudy'/><attribute name='new_degree'/><attribute name='new_address'/><order descending='false' attribute='new_name'/>-<filter type='and'>" +
        "<condition attribute='statecode' value='0' operator='eq'/>" +
        "<condition attribute='new_contactid' value=" + lookupfield + " operator='eq' uitype='contact' />" +
        "</filter></entity></fetch>";
    
        relatedEducation.control.SetParameter("fetchXml", fetchXml);
        relatedEducation.control.refresh();
    
    }

    Thanks for your help!



    • Edited by wikky2007 Thursday, July 11, 2013 12:44 PM removed comment lines
    Thursday, July 11, 2013 4:44 AM
  • You need to get the subgrid using document.getElementyById instead of Xrm.Page.getControl

    //  Load related Education records  
    function loadRelatedEducation() {
        var relatedEducation = document.getElementById("education_subgrid");
        // rest of your code ...



    My blog: www.crmanswers.net

    • Proposed as answer by Guido PreiteMVP Thursday, July 11, 2013 8:05 AM
    • Unproposed as answer by wikky2007 Thursday, July 11, 2013 12:41 PM
    • Proposed as answer by Guido PreiteMVP Friday, July 12, 2013 11:44 AM
    Thursday, July 11, 2013 8:05 AM
  • Guido,

    I am already getting the subgrid with:

    var relatedEducation = Xrm.Page.getControl("education_subgrid");

    The code you are referencing will not work in Update Rollup 12 and up.  Directly accessing the DOM is not supported.  I need to know if it is possible to inject custom fetchxml into a subgrid after Rollup 12.  Do you know of any other methods?  Thanks

    Thursday, July 11, 2013 12:44 PM
  • In CRM 2011 Rollup-12
    subgrid.control.setParameter("fetchXml", fetchXml); is changed to
    subgrid.control.SetParameter("fetchXml", fetchXml);
    same like
    subgrid.control.refresh(); to
    subgrid.control.Refresh();

    All function of subgrid.control will start with capital character

    so you should Change also

    relatedEducation.control.refresh(); to relatedEducation.control.Refresh();


    Muhammad Sohail


    • Edited by sohail450 Friday, July 12, 2013 4:53 AM Chaning
    • Proposed as answer by sohail450 Friday, July 12, 2013 4:53 AM
    Friday, July 12, 2013 4:51 AM
  • Muhammad,

    Thank you for your reply.  Can I ask a couple of additional questions?:

    1.  Why is this the case for Rollup 12 JavaScript?

    2.  Can you point me to the reference in the sdk that says this is true?  Thanks!

    Friday, July 12, 2013 5:33 AM
  • Guido,

    I am already getting the subgrid with:

    var relatedEducation = Xrm.Page.getControl("education_subgrid");

    The code you are referencing will not work in Update Rollup 12 and up.  Directly accessing the DOM is not supported.  I need to know if it is possible to inject custom fetchxml into a subgrid after Rollup 12.  Do you know of any other methods?  Thanks

    There isn't a supported way to change the fetchXml of a subgrid.
    The only way is to manipulate the DOM directly by using unsupported javascript. You are right that document.getElementById is not supported, but this doesn't mean that will not work, is up to you to maintain your code when a new release break something (as rollup12 update).
    To summarize:
    To change the FetchXml you need to get the control by using document.getElementById("");
    To refresh the subgrid you can use the supported method: Xrm.Page.getControl("").refresh;

    My blog: www.crmanswers.net

    • Proposed as answer by Guido PreiteMVP Friday, July 12, 2013 6:02 AM
    • Marked as answer by wikky2007 Thursday, September 5, 2013 3:10 PM
    Friday, July 12, 2013 6:01 AM
  • This blog post explains how to modify the query/results of a sub-grid in CRM 2011 rollup 12 using javascript:

    http://www.magnetismsolutions.com/blog/paul-nieuwelaars-blog/2013/01/24/filter-sub-grid-dynamics-crm-2011-rollup-12-(polaris)

    This includes the SetParameter change already mentioned, and also the work around for .readyState.

    Hope that helps

    Paul


    If my response helped you find your answer please show your thanks by taking the time to "Mark As Answer" and "Vote As Helpful".

    Twitter LinkedIn Facebook Blog Magnetism

    Friday, July 12, 2013 12:03 PM
  • Hi All,

    Below function can be used to change the fetch XML and refresh the Grid control. This is 100% tested and working without an issue with even latest UR 14 on IE, Chrome and Firefox. I haven't access the DOM directly here.

    function PopulateGridFetchXML(sourceFunctionName, subGridName, fetchXML) {
        var subGrid = Xrm.Page.getControl(subGridName);
        if (subGrid._control.get_innerControl() == null) {
                setTimeout(sourceFunctionName, 1000);
                return;
        }
        subGrid._control.get_innerControl().SetParameter("fetchXml", fetchXML);
        // Refresh the grid
        subGrid.refresh();
    }

    Please propose as answer if it's working for you. 

    Cheers,

    Thushara Manchanayake



    IT


    • Edited by tsampath Tuesday, August 13, 2013 10:04 AM
    • Proposed as answer by PraveenK4 Monday, July 28, 2014 9:44 AM
    Tuesday, August 13, 2013 10:02 AM