Recently we had a requirement wherein we wanted to see all the child records of a record in a SubGrid .
We had self-referential (hierarchical relationship) enabled for that entity.

Configuring the Sub Grid on the form.

We have also enabled the Editable grid for the Sub Grid.

The JavaScript code
</p>
<p>function filterSubGrid()<br />
{<br />
// get the current record's guid<br />
var entityId = Xrm.Page.data.entity.getId();</p>
<p>// refer the subgrid<br />
var testGrid = window.parent.document.getElementById("Test");</p>
<p>if (testGrid == null)<br />
{<br />
setTimeout(function () {filterSubGrid(); }, 2000);<br />
return;<br />
}</p>
<p>// fetch xml code using User operator<br />
var fetchXml = "<fetch distinct='false' no-lock='false' mapping='logical'>" +<br />
"<entity name='new_test' >" +<br />
"<attribute name='new_name' />" +<br />
" <attribute name='new_testname' />" +<br />
"<order attribute='new_name' descending='true' />" +<br />
"<filter type='and'>" +<br />
"<condition attribute='new_testid' operator='under' value='"+entityId+"'"+"/>" +<br />
"</filter>" +<br />
"</entity>" +<br />
"</fetch>";</p>
<p>if (testGrid.control != null)<br />
{<br />
testGrid.control.SetParameter("fetchXml", fetchXml);<br />
testGrid.control.refresh();<br />
}<br />
else<br />
{<br />
setTimeout(filterSubGrid, 500);<br />
}<br />
}</p>
<p>
The filtered Sub Grid (editable)

Note :- The JavaScript code is unsupported as we are making use of getElementById instead of Xrm library to access subgrid.
Hope it helps..

























