locked
how can i apply filter in subgrid RRS feed

  • Question

  • Hi,

    I want to display products in purchase order form..so for that i add sub grid in form and add fields of purchase order product.

    and it displays all the products  but i want only that product which has same purchase order id.

    Here I want to display those product which hase same parent purchase order how can i do?

    I have tried this code

     

        var objSubGrid = document.getElementsByName("pop_147");     
        alert(objSubGrid);  

    but i am getting  [object NodeList] so 

    when i am trying to set parameter i am getting error

    objSubGrid.control.SetParameter("layoutXml", LayoutXml);   

    In firefox I am getting this error -TypeError: objSubGrid.control is undefined

    In IE I am getting this error-

    and when i am trying to use

     var objSubGrid = document.getElementsById("pop_147");     
        alert(objSubGrid);  

    I am getting null value..

    How can i solved this problem?


    • Edited by NikkiShah Monday, August 17, 2015 12:20 PM
    Thursday, August 13, 2015 12:58 PM

All replies

  • Please try to help..I am not able to move further
    Monday, August 17, 2015 12:11 PM
  • The "document.getElementById" DOM call is not supported in CRM online with update 1.0.

    Here is alternative information about working with subgrids in CRM online with update 1.0, hope some of this helps.

    https://msdn.microsoft.com/en-us/library/dn932126


    Halldór Jóhannsson


    Monday, August 17, 2015 1:08 PM
  • I have tried many options from this...

        var objSubGridid1 = document.getElementById("pop_147");
        alert(objSubGridid1);                         //Here i am getting  ----null

        var objSubGrid = window.parent.document.getElementById("pop_147");
        alert("id is" + objSubGrid);

        var objSubGrid = document.getElementsByName("pop_147");     
        alert(objSubGrid);                  //Here i am getting  ----[object NodeList]
                                                               //----[object HTML Collection] ---IE

        var subg = Xrm.Page.getControl("pop_147").getGrid();
        alert("subg is" + subg);            //Here i am getting  ----[object Object]

        var subc = Xrm.Page.getControl("pop_147");    
        alert("subc is" + subc);                       //Here i am getting  ----[object Object]

    but none of them works still it gives me this error..unable to get property'setParameter'

    Monday, August 17, 2015 1:11 PM
  • If you are using CRM online with update 1.0 then "getElementById" will not work, not at all.

    Halldór Jóhannsson

    Monday, August 17, 2015 2:00 PM
  • Hello Nikki,

    Take a look at this link: http://blog.navantis.com/dynamically-change-sub-grid-fetchxml-with-a-small-twist-fix/ .

    don't forget the .control property on your subgrid object. 

    Keep in mind this customization is unsupported

    Kind Regards.

    Monday, August 17, 2015 2:13 PM
    • Marked as answer by NikkiShah Tuesday, August 18, 2015 5:06 AM
    • Unmarked as answer by NikkiShah Tuesday, August 18, 2015 5:07 AM
    • Marked as answer by NikkiShah Tuesday, August 18, 2015 5:10 AM
    • Unmarked as answer by NikkiShah Tuesday, August 18, 2015 5:22 AM
    Monday, August 17, 2015 9:57 PM
  • Hi all,

    Thank you for your responce..

    I want to ask that if I want to put custom subgrid through my code how can I put? At present i have put subgrid from admin side.

    If your answer is to use 

     function dynamicallyFilterSubGrid() {
        debugger;

        //var objSubGridid = document.getElementById("pop_147");
        //alert(objSubGridid.innerHTML);                         //Here i am getting  ----null

        var objSubGrid = document.getElementsByName("pop_147");
        alert(objSubGrid);                  //Here i am getting  ----[object NodeList]
                                             //----[object HTML Collection] ---IE

       
        try {        
            var name = Xrm.Page.getAttribute('new_potitle').getValue();
            alert("name is :" + name);          //Here i am getting title of purchaseorder

            var FetchXml = "<fetch distinct='false' mapping='logical' output-format='xml-platform' version = '1.0'>" +
                                "<entity name='new_purchase_order_product'>" +
                                    "<attribute name='new_name'/>" +
                                    "<attribute name='createdon'/>" +
                                    "<attribute name='new_poproductname'/>" +
                                    "<attribute name='new_poproductprice'/>" +
                                    "<filter>" +
                                        "<condition attribute='new_parent_poid' value='" + name + "' operator='eq'/>" +
                                     "</filter>" +
                                "</entity>" +
                            "</fetch>";
                    
            var LayoutXml = "<grid name='resultset' object='8' jump='new_name' select='1' preview='1' icon='1'>" +
                                " <row name='result' id='new_purchaseorderId'>" +
                                        "<cell name='new_purchase_order_productId' width='100' />" +
                                        "<cell name='new_poproductname' width='200' />" +
                                        "<cell name='new_parent_poid' width='200' />" +
                                        "<cell name='new_poproductprice' width='100' />" +
                                    "</row>" +
                             "</grid>";

            objSubGrid.control.SetParameter("layoutXml", LayoutXml);    //Here i am not getting -----TypeError: objSubGrid.control is undefined

            objSubGrid.control.SetParameter("fetchXml", FetchXml);
            objSubGrid.control.Refresh();
        }
        catch (error) {
            alert("error :-" + error)
        }
    }

    then my question is for getElementById("pop_147") i have to put a subgrid and add in form library..

    how can  I perform this action through my code?



    • Edited by NikkiShah Tuesday, August 18, 2015 6:02 AM
    Tuesday, August 18, 2015 5:15 AM
  • hi,

    I am using CRM 2015

    How can iaccess all the parameters  of subgrid?

    like..

    objSubGrid.control.SetParameter("LayoutXml", LayoutXml);  

    if i want to see which parameters used inside subgrid,how can i?

    Can anyone suggest?



    Tuesday, August 18, 2015 9:09 AM
  • Please don't create duplicated threads.

    Dynamics CRM MVP
    My blog

    Tuesday, August 18, 2015 9:46 AM
    Moderator
  • This thread isnot duplicate..
    here i asked that how can i see  other controls of subgrid?
    Tuesday, August 18, 2015 9:49 AM
  • Hi all,

    I want to put subgrid in form dynamically how can i put?and how can i set properties like this..through my code?


    • Edited by NikkiShah Friday, August 21, 2015 9:48 AM
    Friday, August 21, 2015 4:32 AM
  • Can you please give me solution for this..how can i achieve this?

    I am really waiting for your reply

    Monday, August 24, 2015 4:34 AM
  • This is not supported, but you could try this solution - scroll down for the CRM 2015 Update 1 code snippet:

    http://mehmet.ozdemir.id.au/2015/03/crm-2015-filter-a-sub-grid-to-show-data-based-on-hierarchy-using-fetchxml/

    The key is to check to ensure the grid is loaded and keep trying until the grid is loaded.  Then, use window.parent.document.getElementById("subGridId");

    I hope this helps,

    ~ Katie

    Monday, August 31, 2015 5:46 PM