Thursday, 26 March 2015

Refresh SubGrid from JavaScript in CRM 2011, 2013 and 2015

We can refresh the subgrid on the form using JavaScript. Can use the same code on ribbon button click or onchange or wherever depending on the requirement.
 
Xrm.Page.ui.controls.get("SubGridName").refresh();

Here is the way to get the name of the subgrid.




--
Happy CRM'img
Gopinath.

1 comment:

  1. //Set Subgrid Data on change of lookup in CRM 2016 onpremise ver.
    function setCustomers()
    {
    var id = Xrm.Page.getAttribute("vrp_customerid");//Selected Lookup
    var name = null;
    if(id!=null && id.getValue()!=null)
    {
    id = Xrm.Page.getAttribute('vrp_customerid').getValue()[0].id;
    name = Xrm.Page.getAttribute('vrp_customerid').getValue()[0].name;

    var subgrid = window.parent.document.getElementById("Customers"); // Select Subgrid
    if (subgrid == null)
    {
    setTimeout('setCustomers()', 2000);
    return;
    }

    var fetchXml = ""+
    ""+
    ""+
    ""+
    ""+
    ""+
    ""+
    "" +
    "" +
    "" +
    "";

    subgrid.control.SetParameter("fetchXml", fetchXml);
    subgrid.control.refresh();
    }
    }

    ReplyDelete