http://mscrmblogger.com/2011/02/23/crm2011-parent-child-grids-jscript/
function GridFilter(filterControl, sgrid, sfield) {
//var ids = Xrm.Page.getControl(filterControl)._control.get_innerControl().get_selectedIds();
//var ids = document.getElementById(filterControl).control.get_selectedIds();
debugger;
var id = "";
var ids = Xrm.Page.getAttribute(filterControl).getValue();
if (ids.length > 0) {
id = ids[0].id;
}
var updateFetchXml = function (fetchxml, field, id) {
var offset = 19;
var fi = fetchxml.indexOf('
nfetchxml = fetchxml.substring(0, fi);
offset = fetchxml.indexOf('/>', fi) - fi + 2;
} else {
fi = fetchxml.indexOf('
if (fi < 0) {
offset = 0;
fi = fetchxml.indexOf('
closings = '
}
nfetchxml = fetchxml.substring(0, fi);
nfetchxml += '
}
nfetchxml += '
nfetchxml += closings;
nfetchxml += fetchxml.substring(fi + offset);
return nfetchxml;
};
var updateXml = function (grid, xmlfield, subgridfield) {
try {
//var g = Xrm.Page.getControl(grid)._control.get_innerControl();
var g = document.getElementById(grid).control;
var a = g.getParameter(xmlfield);
var b = updateFetchXml(a, subgridfield, id);
g.setParameter(xmlfield, b);
} catch (e) { }
};
// Update the fetchXml
var cGrid = document.getElementById(sgrid).control;
var fetchXML = cGrid.getParameter('fetchXml');
if (fetchXML == null) {
fetchXML = cGrid.getParameter('effectiveFetchXml');
}
if (fetchXML == null) {
fetchXML = cGrid.getParameter('fetchXmlForFilters');
}
fetchXML = updateFetchXml(fetchXML, sfield, id);
cGrid.setParameter('fetchXml', fetchXML);
cGrid.setParameter('effectiveFetchXml', fetchXML);
cGrid.setParameter('fetchXmlForFilters', fetchXML);
// updateXml(sgrid, "fetchXml", sfield);
// // It does not use either of these for filtering, but...
// // I'm not sure where else these could be referenced
// updateXml(sgrid, "effectiveFetchXml", sfield);
// updateXml(sgrid, "fetchXmlForFilters", sfield);
// Refresh the grid
//Xrm.Page.getControl(sgrid).refresh();
document.getElementById(sgrid).control.refresh();
}
function registerSubGridUpdate(filterControl, sgrid, sfield) {
// debugger;
// var p = document.getElementById(filterControl);
var s = document.getElementById(sgrid);
if (s == null || s.readyState != "complete") {
// delay one second and try again. This is required due to grids becoming asynchronous
setTimeout('registerSubGridUpdate("' + filterControl + '","' + sgrid + '","' + sfield + '");', 1000);
return;
}
debugger;
// Enable FetchXML in the grid
// document.getElementById(sgrid + '_filterSet').control.RefreshWithFilters();
// Update to return nothing since it can't link to guid empty
// or click on the first data row, selecting it.
// The getControl for subgrids nolonger works in UR1.
// var r = Xrm.Page.getControl(filterControl)._control.get_nnerControl().get_allRecordIds();
GridFilter(filterControl, sgrid, sfield);
}